无法更新存储在变量中的列

时间:2016-03-07 10:22:15

标签: sql-server stored-procedures

Update XYZ SET February= 562 
WHERE Year = 2016 AND Category = RESOLUTION AND Support_KPI = P1_Gold

在执行此代码时,我得到了结果:

import urllib2

httpProxy = {'username': '------', '-----': '-------', 'host': '------', 'port': '-----'}
proxyHandler = urllib2.ProxyHandler({'http': 'http://'+httpProxy['username']+':'+httpProxy['password']+'@'+httpProxy['host']+':'+httpProxy['port']})
proxyOpener = urllib2.build_opener(proxyHandler)
urllib2.install_opener(proxyOpener)



response = urllib2.urlopen('http://tuberculist.epfl.ch/quicksearch.php?gene+name=Rv0470c')

html = response.readlines()

f = open("/home/zebrafish/Desktop/output.txt",'w')


for l in html:
    if "|Rv0470c|" in l:
        l =  l.split("</small>")[0].split("<TR><TD><small style=font-family:courier>")[1]
        l = l.split("<br />")
        ttl =  l[:1]
        seq =  "".join(l[1:])
        f.write("".join(ttl))
        f.write(seq)
f.close()
  

Msg 207,Level 16,State 1,Line 1   列名称无效&#39; RESOLUTION&#39; 。   Msg 207,Level 16,State 1,Line 1   列名称无效&#39; P1_Gold&#39;

有没有办法摆脱这个错误并正确获取列名?

2 个答案:

答案 0 :(得分:0)

创建动态sql查询并使用 EXEC | EXECUTIVE

执行它

<强>查询

Declare @sql as varchar(max);
Declare @ColumnName varchar(20); 
set @ColumnName = 'January'; -- Change this according to your requirement
select @sql = 'update XYZ set ' + @ColumnName + ' = 876 where Year = 2016;';
execute(@sql);

修改

如果在varchar条件中where键入列,那么我们应该通过将它们加倍来逃避单引号:

<强>查询

Declare @sql as varchar(max);
Declare @ColumnName varchar(20); 
set @ColumnName = 'January'; -- Change this according to your requirement
select @sql = 'update XYZ set ' + @ColumnName +
              ' = 876 where Year= 2016 and Category = ''Resolution'' and Ticket = ''Met'';';
execute(@sql);

答案 1 :(得分:0)

在您的查询中,“分辨率”和“P1_Gold”不是列,但这些是值。在SQL中,varchar值应该用单引号进行修饰。 所以你的查询应该是:

void Main()
{
    var test = Add(() => 5)(6);
    test.Dump();
}

public Func<int, int> Add(Func<int> a)
{
    return (x) => x + a();
}

//returns 11