Server Error in Application

An unhandled exception occurred during the execution of the current web request
posts - 60, comments - 75, trackbacks - 50

My Links

News

Archives

Post Categories

ASP.NET

Passing CSV string as a SQL In Parameter

Some time we requite
select * from tbl where id in (1,2,3) 
if we try like that
declare @csv  varchar(20)
select * from tbl where id in (@csv  ) 
 
Ooops.... error
what's wrong with this...
if you try to print this query you will get the query
select * from tbl where id in ('1,2,3') 
error because @csv cannot be converted to int
 
There is a simple way to resolve this
exec ('select * from tbl where id in ( ' + @csv  + ')' )
 
Cheers!
Mahesh
maheshsingh21@hotmail.com

ASP.NET Interview Questions | C# Interview Questions | .NET Interview Questions | Dot Net Interview Questions | VB.NET Interview Questions | Oracle Interview Questions
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Thursday, October 05, 2006 9:03 AM |

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: