我正在构建一个动态的T-SQL脚本并遇到一些错误。
BIN ?= defaultbrowser
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
CC = gcc
CFLAGS = -O2
.PHONY: all install uninstall clean
all:
gcc -o $(BIN) $(CFLAGS) -framework Foundation -framework ApplicationServices src/main.m
install: all
install -d $(BINDIR)
install -m 755 $(BIN) $(BINDIR)
uninstall:
rm -f $(BINDIR)/$(BIN)
clean:
rm -f $(BIN)
如果我将语句编写为静态语句,则代码有效。当我在动态脚本中运行此错误时。
PRINT 'Convert References into XML fields'
SET @query = N';WITH DCODES AS (' +
'SELECT [id],[Codes],' +
'CAST(''<M>'' + REPLACE([Codes],'','' , ''</M><M>'') + ''</M>'' AS XML) AS [XML_Codes],' +
'CAST(''<M>'' + REPLACE(REPLACE([Descriptions],''&'',''AND''),'','',''</M><M>'') + ''</M>'' AS XML) AS [XML_Desc] ' +
'FROM ##' + @system_name + '_Temp)'
EXEC sp_executesql @query
我试图重写它,但我仍然遇到这个问题。
答案 0 :(得分:1)
下面缺少一行
SET @query = N';WITH DCODES AS (' +
'SELECT [id],[Codes],' +
'CAST(''<M>'' + REPLACE([Codes],'','' , ''</M><M>'') + ''</M>'' AS XML) AS [XML_Codes],' +
'CAST(''<M>'' + REPLACE(REPLACE([Descriptions],''&'',''AND''),'','',''</M><M>'') + ''</M>'' AS XML) AS [XML_Desc] ' +
'FROM ##' + @system_name + '_Temp) select * from DCODES' -- you are missing this