SQL query uses int to query the nvarchar field

Source: Internet
Author: User

If you use 2 to query a comma-delimited field with this ID data, you can use the database built-in function charindex to query the select * from the Users where CHARINDEX (', ' + ' 2 ' + ', ', ', ' +roleid+ ', ' >0 column is the loop to get the data field comma-delimited all the data into a string declare @i int
DECLARE @u int
declare @str nvarchar (max)
Set @i=1
Set @u= (SELECT COUNT (*) from Users)
Set @str = ';
While @i<[email protected]
Begin
Set @str + = (select Roleid from (select Row_number () over (order by ID) ' rowindex ', * from Users) hh where hh.rowindex = @i) + ' ,‘
Set @[email protected]+1
End
Set @str =substring (@str, 1,len (@str)-1)
Print @str
SELECT * from Dbo.fn_split1 (@str, ', ')
SELECT * from Users where CHARINDEX (' 2 ', Roleid) >0

SQL query uses int to query the nvarchar field

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.