1樓:匿名使用者
容易的,用乙個例子來看吧:
declare @sql nvarchar(1000), @where nvarchar(500)
……select @where = 'where 1=1'
if @issuop = 0
select @where = @where + ' and a.issuop = 0'
else if @issuop = 1
select @where = @where + ' and a.issuop = 1'
……create table #tmp(…………)
select @sql = 'insert into #tmp
select series, phenomenon, 0, count(distinct maincode), 0, 0
from view_info_clear ' + @where + ' group by phenomenon, a.series'
exec sp_executesql @sql
思路就是把需要執行的sql語句當作字串,作為nvarchar(1000)型變數@sql的值,然後用 exec sp_executesql @sql 來執行它。
機械公差查表問題,機械製圖中查表問題。
一 20f6,公稱尺寸20,上偏差 0.020,下偏差 0.033,公差值為0.013。即最大極限尺寸為19.98,最大極限尺寸為19.967。二 28f6,公稱尺寸28,上偏差 0.020,下偏差 0.033,公差值為0.013,與20f6相同。即最大極限尺寸為27.98,最大極限尺寸為27.96...
SQL語句問題,SQL語句問題
select identity int,1,1 as newid,sale.prtid as id,products.prtname as 商品名稱,sum sale.prtnum as 銷售總量 into a from sale,products where sale.prtid products...
sql查詢問題,sql查詢問題
select aa01 sum cc02 from aa01inner join bb01 on aa01 bb01 iner join cco1 on bb02 cc02 group by aa01 大概語句就是這樣,bb01和cc01是通過bb02和cc02關聯 select a.aa01,a....