在.net中附近的语法错误。在asp。#c [英] Incorrect Syntax near S.. in asp .net c#
本文介绍了在.net中附近的语法错误。在asp。#c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友们,
我在s和Max附近有不正确的语法,在最后3行有10个..有什么问题请问我有什么问题..
选择 10prdp_totalcount 为 [10prdp],
Rate_totalamount as [Rate],
D-Clamp_totalcount as [D-Clamp],
Rate_totalamount as [Rate]
来自
(
选择 DPNo,
ItemName + ' _' + col,
MatQty
from
(
选择 DPNo,ItemName,
cast(Rate as 数字( 10 , 2 ))率
来自 Vw_DailyEntry
)src
unpivot
(
MatQty
col in (rate)
)unpiv
)s
pivot
(
Max(MatQty)
for ItemName in (10prdp_totalcount,Rate_totalamount,
Clamp_totalcount,Rate_totalamount)
)piv
order by ItemName
解决方案
这么多问题:
1:列名不能以数字开头:10prdp_totalcount=_ 10prdp_totalcount
1a:除非括号内:[10prdp_totalcount]
2:你必须为anon表类型中的每一列命名:ItemName +'_'+ col = ItemName +'_'+ col as ItemnameCol,
3:列名不能包含操作数:D -Clamp_totalcount=D_Clamp_totalcount
3a:除非括号内:[D-Clamp_totalcount]
4:pivit列名必须是唯一的:2xRate_totalamount
5:order by必须是相同范围的计算列:按ItemName排序=按[D-Clamp]排序
得到那些排序,然后看看你在哪里^ _ ^
Andy
好的 - 解决第二个问题:
首先运行:
选择 DPNo,
ItemName + ' _' + col col,
MatQty
来自(
选择
DPNo,
ItemName,
cast(MatQty as numeric ( 10 , 2 ))mtqty,
cast(Rate as numeric ( 10 , 2 ))rate
from
Vw_DailyEntry
)src
unpivot(
MatQty
col in (rate,mtqty)
)unpiv
注意[col]中的名称 - 这些是数据透视中可用的列名。
其中一些名字以数字开头。没关系 - 括起来:
for col in([10prdp_rate],[10prdp_mtqty],[10p_rate],[10p_mtqty],[D-Clamp_rate],[D-Clamp_mtqty] ],[D_C_rate],[D_C_mtqty])
更新这些和选择列以获取一些值
PS:这是我的测试数据:
声明@Vw_DailyEntry表(
DPNo int identity(1,1)主键不为null,
ItemName nvarchar(max)not null,
MatQty numeric(10,2)not null,
费率数字(10,2)非空)
INSERT INTO @Vw_DailyEntry(
ItemName,
MatQty,
Rate
)
值
('10prdp',1.0,1.0),
('10prdp',2.1,2.1),
('10prdp',3.2,3.2),
( 'D-Clamp',4.3,4.3),
('10p',5.4,5.4),
('D_C',6.5,6.5),
('10prdp',7.6, 7.6),
('D_C',8.7,8.7),
('D_C',9.8,9.8),
('D-Clamp',10.9,10.9),
('10prdp',11.10,11.10),
('10p',12.11,12.11),
( 10p',13.12,13.12),
('D_C',14.13,14.13),
('D-Clamp',15.14,15.14),
('D_C',16.15,16.15) ),
('10p',17.16,17.16),
('D_C',18.17,18.17),
('10p',19.18,19.18),
(' D_C,20.19,20.19)
Dear Frnds,
I have incorrect syntax near s and Max and 10 in last 3 lines.. what is the problem anyone tell me pls..
select 10prdp_totalcount as [10prdp],
Rate_totalamount as [Rate],
D-Clamp_totalcount as [D-Clamp],
Rate_totalamount as [Rate]
from
(
select DPNo,
ItemName +'_'+col,
MatQty
from
(
select DPNo, ItemName,
cast(Rate as numeric(10, 2)) rate
from Vw_DailyEntry
) src
unpivot
(
MatQty
for col in (rate)
) unpiv
) s
pivot
(
Max(MatQty)
for ItemName in (10prdp_totalcount, Rate_totalamount,
Clamp_totalcount, Rate_totalamount)
) piv
order by ItemName
解决方案
So many issues:
1: column names can not start with a digit: "10prdp_totalcount" = "_10prdp_totalcount"
1a: unless bracketed: "[10prdp_totalcount]"
2: you must name every column in anon table types: "ItemName +'_'+col = ItemName +'_'+col as ItemnameCol,"
3: column names cannot contain operands: "D-Clamp_totalcount" = "D_Clamp_totalcount"
3a: unless bracketed: "[D-Clamp_totalcount]"
4: pivit column names must be unique: 2x"Rate_totalamount"
5: order by must be a calculated column of the same scope: "order by ItemName" = "order by [D-Clamp]"
get those sorted, then see where you are ^_^
Andy
Ok - solution to second problem:
First run this:
select DPNo, ItemName +'_'+col col, MatQty from( select DPNo, ItemName, cast(MatQty as numeric(10, 2)) mtqty, cast(Rate as numeric(10, 2)) rate from Vw_DailyEntry ) src unpivot( MatQty for col in (rate,mtqty) ) unpiv
Notice the names in [col] - These are the column names available in the pivot.
Some of these names start with a digit. That's ok - bracket them:
for col in ([10prdp_rate], [10prdp_mtqty], [10p_rate], [10p_mtqty], [D-Clamp_rate], [D-Clamp_mtqty], [D_C_rate], [D_C_mtqty])
Update these and the select columns to get some values
PS: this was my test data:
declare @Vw_DailyEntry table ( DPNo int identity(1,1) primary key not null, ItemName nvarchar(max) not null, MatQty numeric(10, 2) not null, Rate numeric(10, 2) not null) INSERT INTO @Vw_DailyEntry( ItemName, MatQty, Rate ) values ('10prdp',1.0,1.0), ('10prdp',2.1,2.1), ('10prdp',3.2,3.2), ('D-Clamp',4.3,4.3), ('10p',5.4,5.4), ('D_C',6.5,6.5), ('10prdp',7.6,7.6), ('D_C',8.7,8.7), ('D_C',9.8,9.8), ('D-Clamp',10.9,10.9), ('10prdp',11.10,11.10), ('10p',12.11,12.11), ('10p',13.12,13.12), ('D_C',14.13,14.13), ('D-Clamp',15.14,15.14), ('D_C',16.15,16.15), ('10p',17.16,17.16), ('D_C',18.17,18.17), ('10p',19.18,19.18), ('D_C',20.19,20.19)
这篇关于在.net中附近的语法错误。在asp。#c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文