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
 How to get single quotes for every row ???

Author  Topic 

mohan123
Constraint Violating Yak Guru

252 Posts

Posted - 2013-02-05 : 23:47:50
hello all,

i am havind the codes like this

48267
7998
51075
52220
57627
58772

is there any function or query

to make this codes

'48267'
'7998'
'51075'
'52220'
'57627'
'58772'

in mssql OR eXCEL ....Suggest me

P.V.P.MOhan

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-02-06 : 00:07:43
is that string or numbers ?

if it is string just simple
select '''' + string_column + '''' from yourtable


if it is numbers, you will have to convert to string frist
select '''' + convert(varchar(10), numbers_column) + '''' from yourtable



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-06 : 00:13:16
nope. you've to write one

SELECT '''' + CAST(Column AS varchar(100)) + '''' FROM table

in case column is already of character type, you can dispense with the CAST part

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-06 : 00:15:28
ah...didnt refresh

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

mohan123
Constraint Violating Yak Guru

252 Posts

Posted - 2013-02-06 : 00:34:17
khtan and visakh it worked like charm.But i did this one in excel
by following this steps :
1) copied all rows in Excel column and beside columns i gave " quotes on both sides.

then copied in mssql and written LTRIM and RTRIM but your query is so accurate.I will use this one

P.V.P.MOhan
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-06 : 00:37:55
you can use both ways. i also use Excel for generating queries on the fly

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

mohan123
Constraint Violating Yak Guru

252 Posts

Posted - 2013-02-06 : 00:40:45
Excel can be used to generate MSSQL queries????HOW

P.V.P.MOhan
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-06 : 00:55:40
copying data over sheet and then applying excel formulas to generate values on the fly

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-02-08 : 07:47:51
Do it in EXCEL that will be very easy

Madhivanan

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

- Advertisement -