Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Getting a ' in the result ie '01234

Author  Topic 

sqltenderfoot
Starting Member

5 Posts

Posted - 2010-11-02 : 08:13:19
Hi Guru's,

I am running a query on SQL 2005, and am copying the result manually to Excel. Unfortunately, a number as 01234 changes in 1234 in Excel. So I want to concatenate ' and 01234 in the output, so Excel understands it is a text.

The problem is that when I try i.e. select ''01234', SQL doesnt like this.
Any suggestions?

best regards and thanks in advance.

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2010-11-02 : 08:23:10
format the column as text before you do the copy.

Be One with the Optimizer
TG
Go to Top of Page

sqltenderfoot
Starting Member

5 Posts

Posted - 2010-11-02 : 08:32:49
Hi TG,
Thanks for reply, this is indeed how I am doing it now.
However I like to automate this.

AK
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-02 : 08:49:49
Try this

select ''''+cast(01234 as varchar(10))


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sqltenderfoot
Starting Member

5 Posts

Posted - 2010-11-02 : 08:59:36
Thanks Madhivanan,

This is what I was looking for.

AK
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-02 : 11:38:12
quote:
Originally posted by sqltenderfoot

Thanks Madhivanan,

This is what I was looking for.

AK


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -