sql server - T sql select int value as casting varchar -


i have stored procedured called getreport

customers.branches_id int type  

however @branches parameter varchar

@branches "10,13534,554,776,767"

i want search 10,13534,554,776,767 in branches_id if cast/convert varchar not working me.

alter procedure [dbo].[getreport]   @fromdate datetime, @todate datetime, @branches varchar (500) = null  begin  set nocount on;   select * customers  (customers.createddate between @fromdate , @todate) ,  (@branches null or convert(varchar(500), customers.branches_id) in(@branches )) -- part not working me   end 

how can solve problem how can search multiple comma varcvhar inside of int column ?

thanks.

there @ least 4 methods this. here one:

select * customers customers.createddate between @fromdate , @todate ,  (@branches null or branches_id     in(          select  y.i.value('(./text())[1]', 'nvarchar(4000)')             ( select    x = convert(xml, '<i>' + replace(@branches, ',', '</i><i>')                     + '</i>').query('.')                  )          cross apply x.nodes('i') y ( ))) 

look other methods here http://blogs.msdn.com/b/amitjet/archive/2009/12/11/sql-server-comma-separated-string-to-table.aspx

but can use table valued types type of work if use sql server 2008 or higher.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -