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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Concatenated string issue...

Author  Topic 

companionz
Yak Posting Veteran

54 Posts

Posted - 2009-04-17 : 08:57:08
Guys,

I am passing this value to a procedure as an input parameter:

'300617901GB7~300617901GB8~300617901GCF'

and inside am making it as :

'300617901GB7','300617901GB8','300617901GCF'

and then passing it to a select query:


Select * from TestTable where TestNumber in (@SLNumberFinal)

But this doesn't return me any value...

but if i pass a parameter to proc like this '300617901GB7' it gives a value..

I did check for this value and it is getting passed to the sql query as : 300617901GB7
i mean with no inverted commas..

i even tried passing :

300617901GB7','300617901GB8','300617901GCF

Can anyone help me resolve this issue?

Thanks,
Sourav

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-17 : 09:04:53
Select * from TestTable where '~'+@SLNumberFinal+'~' like '%~'+TestNumber+'~%'


Madhivanan

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

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-04-17 : 23:13:44
try this one too
declare @str varchar(128)
set @str ='300617901GB7','300617901GB8','300617901GCF'

exec('Select * from TestTable where testnumber in ('+@str+')')
if testnumber is integer value use this one
exec('Select * from TestTable where cast(testnumber as varchar(128) in ('+@SLNumberFinal+')')
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-18 : 02:54:56
quote:
Originally posted by bklr

try this one too
declare @str varchar(128)
set @str ='300617901GB7','300617901GB8','300617901GCF'

exec('Select * from TestTable where testnumber in ('+@str+')')
if testnumber is integer value use this one
exec('Select * from TestTable where cast(testnumber as varchar(128) in ('+@SLNumberFinal+')')



That wont work. In this approach, you need to put single quote around each value

Madhivanan

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

- Advertisement -