Toad 和 SQL Server 2005

发布于 2024-11-02 03:59:34 字数 723 浏览 4 评论 0原文

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条件,我需要进行更改。

您能告诉我为什么他们使用 '''''+@begdate''''' 吗?我可以使用'+Bedate'吗? 我的意思是为什么他们每一边都使用 '''''

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 + ''''' '')'

Here is the where condition which is already written and I need to make changes.

Can you please tell me why they are using '''''+@begdate'''''? Can i use '+Bedate'?
I mean why they are using ''''' each side?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

始终不够 2024-11-09 03:59:34

在 SQL Server 中尝试此操作:

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

您会注意到该项给出:

''someval''

在 SQL Server 中 '' 将等同于单引号字符,因此上面的行是

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

Try this in SQL Server:

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

You notice that item gives:

''someval''

In SQL Server '' will equate to a single quote character, so the above line is

select [open string][single quote][single quote]someval[single quote][single quote][close string]
天荒地未老 2024-11-09 03:59:34

在没有看到 SQL 的其余部分的情况下,我的猜测是:

  1. 在动态 SQL 中使用,因为 @BegDate 是一个变量,并且语句以单引号结尾,
  2. 数据包含一堆单

引号不应该只是 '+BegDate' 因为它是一个变量,并且剥离 @ 会导致它被评估为一个字段。

如果您只是想减少单引号的数量,我想原作者将它们放在那里是有原因的。您可以使用原始单引号运行查询,然后使用减少的单引号再次运行查询,看看是否获得相同的结果集。

Without seeing the rest of the SQL, my guesses would be:

  1. for use in dynamic SQL as @BegDate is a variable and you have the statement ending with a single quote
  2. the data contains a bunch of single quotes

You should not be able to just '+BegDate' because it's a variable and stripping the @ would cause it to be evaluated as a field.

If you meant to just reduce the number of single quotes, I would imagine the original author put them there for a reason. You can run the query with the original single quotes and again with the reduced single quotes and see if you get the same result set.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文