如何修复')'附近的语法不正确

时间:2016-07-25 12:57:06

标签: sql-server

我尝试了很多但是找不到这个查询有什么问题,它给了我这个错误:

  

')'附近的语法不正确。

.productNumber

也适用于访问数据库,但不适用于sql server。

3 个答案:

答案 0 :(得分:2)

您的问题是您尝试从子查询中进行选择而不为结果集指定别名。

您所要做的就是从此处更改您的查询

string query = "select sum(See) as[All] ,(select top 1 See from StateSite
where StatDate=@StatDate)as[Now], (select top 1 See from StateSite where
StatDate=@Yesterday)as[Last],(select sum(See)  from  (select top 7 * from
StateSite order by ID desc))as[week] From StateSite";

到此

string query = "select sum(See) as[All] ,(select top 1 See from StateSite
where StatDate=@StatDate)as[Now], (select top 1 See from StateSite where
StatDate=@Yesterday)as[Last],(select sum(See)  from  (select top 7 * from
StateSite order by ID desc) as [subQuery])as[week] From StateSite";

答案 1 :(得分:2)

SELECT
    [All] = SUM(See),
    [Now] = MAX(CASE WHEN StatDate = @StatDate THEN See END),
    [Last] = MAX(CASE WHEN StatDate = @Yesterday THEN See END),
    [week] = SUM(CASE WHEN RowNum < 8 THEN See END)
FROM (
    SELECT *, RowNum = ROW_NUMBER() OVER (ORDER BY id DESC)
    FROM StateSite
) t

答案 2 :(得分:0)

您可以尝试直接将查询运行到数据库并检查语法是否正确。您的查询可能存在多个()。例如,在我的情况下,为IN子句传递的参数为空,从而创建了类似let transform = label.transform label.transform = transform.concatenating(CGAffineTransform(rotationAngle:CGFloat(textModel.rotation))) //After that I applied previous Center to label label.center = center // This is the main code where I am applying transformation to CGContext. After a long search, I set some frames for some directions also after rotation applied, but didn’t get any success. let c = UIGraphicsGetCurrentContext() c?.saveGState() c?.translateBy(x: frame.origin.x, y: frame.origin.y) c?.concatenate(label.transform) // setting frames after rotation if rotation < 0 { if transform.a < 0 { c?.translateBy(x:-(label.boundsWidth+(label.boundsHeight/2)), y: -(label.bounds.height/2)) } else { c?.translateBy(x:-(label.size.height/2), y: (label.size.height/2)) } } else if rotation > 0 { if transform.a < 0 { c?.translateBy(x:-((label.boundsWidth)-(label.boundsHeight)), y: -((label.size.height)-(label.boundsHeight/2))) } else { c?.translateBy(x: (label.boundsHeight/2), y: -(label.boundsHeight/2)) } } c?.restoreGState() 的查询,因此出错了。