SQL Server dynamically generates temporary tables

Source: Internet
Author: User
If object_id ('[tmp_processinfo]') is not null drop table [tmp_processinfo] Create Table tmp_processinfo (finterid int, fname varchar (255) -- insert tmp_processinfo -- select 0, 'A' Union all -- select 1, 'B' -- select * From tmp_processinfodeclare @ querystr varchar (255), @ SQL varchar (1000) set @ querystr = 'and FTYPE = 0 and fprocessinfoid in (122,150,)' set @ querystr = Replace (@ querystr, 'and FTYPE = 0 ','') set @ querystr = Replace (@ querystr, 'fprocessinfoid', 'finterid') set @ SQL = 'insert tmp_processinfo select finterid, fname from t_cy_processinfo where 1 = 1' + @ querystrset @ SQL = @ SQL + 'Union all select 0, ''' print @ sqlinsert tmp_processinfo select finterid, fname from t_cy_processinfo where 1 = 1 and finterid in (0, 53, 122,150) Union all select 0, ''select * From tmp_processinfo
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.