Mysql/sqlserver where in parameter passing

Source: Internet
Author: User

Mysql/sqlserver where in parameter passing problem parameter: @ p0 = 1, 2, 3, 4 1. the common query is as follows: select * from table_name t where t. field1in (1, 2, 3, 4 ,...); select * from table_name t where t. field1in (@ p0); the final SQL statement is select * from table_name t where t. field1in ('1, 2, 3, 4 ,... '); only t. the result of field1 = 1 (the specific reason for finding the first record to be studied) is not feasible if all parameters can be found. In this case, use solution 2 in step 2. find_in_set use this method to obtain select * from table_name t where find_in_set (t. field1, '1, 2, 3, 4 '); The following is the related sorting and sqlserver solution MySQL/sqlserver query in operation query results are displayed in the in set Order select * from ibs6_terminal_adv_inf where id in (, 15) order by field (id, 16,14, 15) select * from ibs6_terminal_adv_inf where id in (16,14, 15) order by find_in_set (id, '16, 14,15 ') select * from ibs6_terminal_adv_inf where id in (16,14, 15) order by substring_index ('16, 14,15', id, 1) the result shows in sequence that sqlserver uses the following statement select * from ibs6_terminal_adv _ Inf where id in (16,14, 15) order by CHARINDEX (',' + ltrim (id) + ', 16,14, 15 ,') "This method has not been tested. If you have tested it, you can check the result. There are many commas (,) in it, so you cannot leave it empty ~~~

Related Article

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.