string AA="1,2,3"; string sqltxt="Select* from where inch ("+AA+") ";
It is possible to convert a string such as "one-way" to a temporary table with one column, 3 rows, and one item in each row (separated by commas)
This function can be written like this:
GO/** * * * object:userdefinedfunction [dbo]. [Strtotable] Script DATE:2016/3/1 18:53:35 * * * * **/SETAnsi_nulls onGOSETQuoted_identifier onGOALTER Function [dbo].[strtotable](@str varchar( +))Returns @tableName Table(IDvarchar( -)) as--This function is used to convert multiple data strings separated by commas into a single column of a table, for example, the string ' 1,2,3,4,5 ' will program a table, this tableBeginSet @str = @str+','Declare @insertStr varchar( -)--the first string after interceptionDeclare @newstr varchar( +)--string remaining after the first string is interceptedSet @insertStr = Left(@str,charindex(',',@str)-1)Set @newstr = Stuff(@str,1,charindex(',',@str),"')Insert @tableName Values(@insertStr) while(Len(@newstr)>0)begin Set @insertStr = Left(@newstr,charindex(',',@newstr)-1) Insert @tableName Values(@insertStr) Set @newstr = Stuff(@newstr,1,charindex(',',@newstr),"')EndReturnEND
And then the SQL statement can do that.
Declare str Vchar (+)setstr='All-in-all' Select * from where inch (Select from strtotable (@str))
In SQL Server, a string that is separated by a comma "," is converted to a table and applied with the in condition