I have nvarchar (MAX) in my stored procedure that contains a list of int values, I did it like it is not possible to pass an int list to my stored procedure , but now I get the problem, since my data type is int, and I want to compare the list lines. Is there any way I can do the same?
---myquerry----where status in (@statuslist)
but the status list now contains string values, not int, so how do I convert them to INT?
UPDATE:
USE [Database] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[SP] ( @FromDate datetime = 0, @ToDate datetime = 0, @ID int=0, @List nvarchar(MAX) //This is the List which has string ids// )
A.S. SET FMTONLY OFF; DECLARE @sql nvarchar (MAX), @paramlist nvarchar (MAX)
SET @sql = 'SELECT ------ and Code in(@xList) and -------------' SELECT @paramlist = '@xFromDate datetime,@xToDate datetime,@xId int,@xList nvarchar(MAX)' EXEC sp_executesql @sql, @paramlist, @xFromDate = @FromDate ,@ xToDate=@ToDate ,@ xId=@ID ,@ xList=@List PRINT @sql
Therefore, when I implement this function, which is broken, I cannot specify a character or separator, since it does not accept it as (@List, ',').
or (',' + @List + ',').
Iti tyagi
source share