Exec and sp_executesql in SQL Server

Source: Internet
Author: User

Reference: http://www.cnblogs.com/xbf321/archive/2008/11/02/1325067.html

Exec('Select * From tablename ')

 Declare   @ Slideavg   Real  Declare   @ Sql1   Nvarchar ( 1000  )  Set   @ Sql1  =  '  Select@ Slideavg= AVG (VAL) from S '  +  @ Stationid  +  '  Hn where channel_num =  '''  +  @ Channel_num  +  '''  And date_time> =  '''  +  Convert ( Nvarchar , @ Oldh , 120 ) +  '''  And date_time <=  '''  +  Convert ( Nvarchar , @ H24 , 120 ) +  '''' ExecSp_executesql@ Sql1, N'@ Slideavg Real Output',@ SlideavgOutput  If   @ Slideavg   Is   Not   Null   And   @ Slideavg  <>  ''  Begin  ......... End 

 

 

 Select  C0252_id, c0252_name, c0252_addr ,((  Select   Top   1 C0003_name From DBO. t0003_districtinfo Where C0003_code Like   '  %  '  +  Substring (C0003_areacode,1 , 4 ) +  '  %  ' ) +  '   '  + C0003_areaname) As  Areaname  From DBO. t0252_manufacturer

 

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.