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
 Remove single code from varchar type

Author  Topic 

anujpratap84
Starting Member

45 Posts

Posted - 2011-02-15 : 11:09:23
Hi All,

I am passing comma separated ids to a varchar variable in SP using C#. SP query like:
Select * From player Where ID IN('1')
It's working fine for a single record but if record is more than 1 Like '1,2,3,4' it throws an error on converting '1,2,3,4' to data type int.
Can i remove single code from this.
I don't want to use dynamic query.
Any body have any idea.
Thanks in advance.

Anuj Pratap Singh

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-02-15 : 11:29:47
Yes. and the error is quite clear as you are trying to compare a string value with an Integer column.

its good to avoid Dynamic SQL for such operation and as an alternative you should implement CSV to table conversion ... google the highlighted you will get a good details.

Go to Top of Page

anujpratap84
Starting Member

45 Posts

Posted - 2011-02-15 : 13:03:54
quote:
Originally posted by MIK_2008

Yes. and the error is quite clear as you are trying to compare a string value with an Integer column.

its good to avoid Dynamic SQL for such operation and as an alternative you should implement CSV to table conversion ... google the highlighted you will get a good details.




Thanks you, MIK_2008.

Anuj Pratap Singh
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-02-16 : 09:39:08
or pass ids to variable @id and use

Select * From player Where '%,'+@id+',%' ','+cast(ID as varchar(10))+','

Madhivanan

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

- Advertisement -