Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I've to write a procedure in which i need to pass a parameter like..Create Procedure Test_Proc @FromDt DateTime, @ToDt DateTime, @CompanyUid IntBeginselect name from company where uid in @Companyuid--- i mean, i can have multiple companies for this parameter..What should be the datatype then.. and if possible give me an example of how to execute also..How to go about this?Thanks,Sourav
declare @Companyuid varchar(max),@str varchar(max)select @Companyuid ='1,2,5',@str =''select name from company where '%,' + @Companyuid+ ',%' LIKE '%,' + CAST( id AS VARCHAR(255)) +',%' select @str = 'select name from company where cast(id as varchar) in('+@Companyuid+')')exec (@str)select name from company where patindex('%,' + CAST( id AS VARCHAR(255)) +',%',','+@Companyuid+',' )>0