汇总一个棘手的SQL查询

编程入门 行业动态 更新时间:2024-10-24 20:17:02
本文介绍了汇总一个棘手的SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用SQL 2008机器,似乎无法使查询正常工作. 我的SQL查询是:

I am working on a SQL 2008 machine and cannot seem to get the query to work. My SQL query is :

select q.Document DOC from references q, equiprates e where e.MachineID=q.UnitID'

q.Document取消的行是:

The rows retruned by q.Document is:

5570_RESTAURANT.pdf 5650_RESTAURANT.pdf 5110_RESTAURANT.pdf

但是,我需要表行如下:

However, I need the table rows to be as follows:

餐厅文件

<a href="Javascript:ViewPDFDoc('5570_RESTAURANT.pdf')" class="Link">5570_RESTAURANT.pdf</a> <a href="Javascript:ViewPDFDoc('5650_RESTAURANT.pdf')" class="Link">5570_RESTAURANT.pdf</a> <a href="Javascript:ViewPDFDoc('5110_RESTAURANT.pdf')" class="Link">5570_RESTAURANT.pdf</a>

因此,我尝试按以下格式设置我的选择字符串:

So I am trying to format my selecct string as follows:

Select @sSQL = 'select q.Document DOC, ''<a href="Javascript:ViewFile('''''+q.Document+''''''')" class="Link">''+q.Document+''</a>'' ''Restaurant Document'', from references q, equiprates e where e.MachineID=q.UnitID'

我的错误消息是:

Msg 4104,第16级,状态1,第3行

Msg 4104, Level 16, State 1, Line 3

多部分标识符"q.Document"无法绑定.

The multi-part identifier "q.Document" could not be bound.

有什么办法解决这个问题吗? 我尝试过Google,但没有运气.

Any ideas how to resolve this? I tried google, but no luck.

推荐答案

您的单引号是错误的(我还建议您改用更现代的INNER JOIN语法).但是,为什么应用程序不能简单地在DOC列周围添加HTML?在服务器上添加所有HTML,并通过网络发送所有这些字节,似乎很浪费时间(显然,要复杂得多).

Your single quotes are just wrong (I also recommend shifting to more modern INNER JOIN syntax). But why can't the application simply add the HTML around the DOC column? Seems wasteful (never mind more complex, obviously) to add all that HTML at the server, and send all those bytes over the wire.

DECLARE @sSQL NVARCHAR(MAX); SET @sSQL = N'SELECT DOC = q.Document, [Restaurant Document] = ''<a href="Javascript:ViewFile('''''' + q.Document + '''''');" class="Link">'' + q.Document + ''</a>'' FROM references AS q INNER JOIN equiprates AS e ON q.UnitID = e.MachineID'; PRINT @sSQL;

更多推荐

汇总一个棘手的SQL查询

本文发布于:2023-11-22 05:29:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616145.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:棘手   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!