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
 Fill Column Value to VarChar String

Author  Topic 

jp2code
Posting Yak Master

175 Posts

Posted - 2009-01-06 : 21:47:51
What I'm trying to do but won't work:

declare @colN varchar(255)
set @colN=select columnN from Table where ColumnKey='111'

That doesn't work though.

How do I write this correctly?

FWIW: ColumnN contains a comma separated input string that I'll have to parse right afterwards.


Avoid Sears Home Improvement

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-06 : 22:49:56
declare @colN varchar(255)
set @colN=select substring(columnN,charindex(',',columN,1)+1,len(columN)) from Table where ColumnKey = '111'


Jai Krishna
Go to Top of Page

w152681
Starting Member

1 Post

Posted - 2009-01-06 : 23:52:18
declare @colN varchar(255)
select @colN=columnN from Table where ColumnKey='111'


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-07 : 03:15:06
quote:
Originally posted by Jai Krishna

declare @colN varchar(255)
set @colN=select substring(columnN,charindex(',',columN,1)+1,len(columN)) from Table where ColumnKey = '111'


Jai Krishna


it should be

declare @colN varchar(255)
set @colN=(select substring(columnN,charindex(',',[columN],1)+1,len([columN])) from [Table] where ColumnKey = '111')
Go to Top of Page

jp2code
Posting Yak Master

175 Posts

Posted - 2009-01-07 : 16:46:59
Thanks!


Avoid Sears Home Improvement
Go to Top of Page
   

- Advertisement -