2011-04-18 141 views
1
where a.system_nr =''''5300'''' and 
     a.external_status_cd = '''''''' and 
     a.cust_acct_id = b.rel_cust_acct_id and 
     b.cust_acct_id = c.cust_acct_id and 
     c.cust_acct_id = d.cust_acct_id and 
     d.acct_status_cd = ''''OPEN'''' and 
     d.time_mnth_gen_id =''''' + @BegDate + ''''' and 
     a.cust_acct_id = e.cust_acct_id and 
     e.tran_dt >=''''' + @BegDate + ''''' and 
     e.tran_dt<=''''' + @EndDate + ''''' and 
     d.portfolio_cd = ''''HEQ'''' and 
     a.time_mnth_gen_id =''''' + @BegDate + ''''' '')' 

這裏是where條件已經寫好,我需要進行更改。Toad和SQL Server 2005

你能告訴我他們爲什麼使用'''''[email protected]'''''?我可以使用'+Bedate'嗎? 我的意思是他們爲什麼每面都使用'''''

+1

因爲列值中包含單引號? – 2011-04-18 06:28:15

+0

我懷疑你認爲構建動態查詢的完整語句太大而不能包含在你的問題中。但是在完整版本中顯示哪對引號包含了什麼會容易得多。不過,基本上答案是:它與引用引號字符(''')有關。 – 2011-04-18 07:58:31

回答

0

試試這個在SQL Server:

select '''''someval''''' 

您發現該項目得到:

''someval'' 

在SQL Server ''將等同於一個單引號字符,所以上面的線是

select [open string][single quote][single quote]someval[single quote][single quote][close string] 
0

沒有看到其餘的SQL,我的猜測是:

  1. 對動態SQL中使用的@BegDate是一個變量,你必須用單引號
  2. 的數據,包含了一些單引號

的結束聲明你不應該能夠公正'+BegDate',因爲它是一個變量,剝離@會導致它被評估爲一個字段。

如果你只是想減少單引號的數量,我會想像原作者把它們放在那裏的原因。您可以使用原始單引號運行查詢,再次使用簡化的單引號運行該查詢,然後查看是否獲得相同的結果集。