SQL Server 2008 R2的查询错误:附近有语法错误:“
我有给我一定的查询问题,我不知道如何解决这个问题..这里是查询..SQL Server 2008 R2的查询错误:附近有语法错误:“
SELECT dcm.code DCM_No,
dcm.datetime_created DCM_Date,
lne.seq_number,
par.code,
par.description particular,
ft.description fee_type,
lne.amount,
case when lne.drcr =1 then 'Debit' else 'Credit' end DrCr,
case when isnull(dcm.is_sd,'N') = 'Y' then 'Salary Deduction' else null end is_sd,
org.description Company,
org.postal_address company_addr,
'S.Y. ' + substring(sy.school_year,1,4)+'-'+substring(sy.school_year,5,4) +' '+sem.description SY,
entity_a.code + ' - ' + coalesce(entity_a.stud_lname,'') +', '+coalesce(entity_a.stud_fname,'') +' '+coalesce(entity_a.stud_mname,'') Student,
case when isnull(dm.description2,'') = '' then
crs.course_short_name + '-'+convert(char(1),entity_a.stud_grade)
else crs2.course_short_name + '-'+convert(char(1),reg.stud_grade) end as Course,
isnull(dm.description2,'Not Enrolled')
FROM es.lib_rgn_students entity_a
left join ars.ars_dcm dcm on dcm.entity_id = entity_a.id
LEFT JOIN afs.entity entity_b ON dcm.prepared_by_id = entity_b.id
LEFT JOIN ua.user_account ON dcm.prepared_by_id = ua.user_account.id
left join ars.ars_dcm_line lne on lne.ars_dcm_id = dcm.id
left join es.lib_fin_fees_master par on par.id = lne.ars_particular_id
left join es.lib_fin_feetype ft on ft.code = lne.fee_code
left join es.stp_sysem sy on sy.id = dcm.period_id
inner join es.stp_semesterms sem on sem.code = sy.semester and sem.trimester = 0
inner join afs.organization org on org.id = sy.company_id
inner join es.lib_crs crs on crs.id = entity_a.course_id
left join es.trn_rgn_reg_hdr reg on reg.period = sy.id and reg.stud_id = :as_studid
left join document_status_map dm on dm.code = reg.document_status
left join es.lib_crs crs2 on crs2.id = reg.course_id
WHERE
(dcm.entity_id = :as_studid) AND
(dcm.period_id = :as_period) AND
(dcm.document_status_code not in(2,3))
,我有这样的错误:
Incorrect syntax near ':'.
请帮助我不擅长这个:(
感谢
的:as_studid
和:as_period
事情13759某些客户端软件,该查询的最有可能的参数。在实际执行查询之前,:name
位被@P1
或@as_studid
替换(通常由一些中间层软件),所以服务器从不会在那里看到冒号(并且从不抱怨)。
如果您不是客户端软件开发人员,并且被简单地分配了执行查询任务的任务,那么您需要手动应用上述转换。我建议你声明变量@as_studid
和@as_period
并分别用它们代替:as_studid
和:as_period
。另外,您可能需要为它们分配一些值,以便在运行查询时可以看到一些结果。下面是修改后的脚本如何可能看起来像一个例子:
DECLARE
@as_studid int,
@as_period int; /* those are just my guesses, the actual types
might need to be something other than int */
SET @as_studid = 10;
SET @as_period = 20; /* again, those are arbitrary values off the top
of my head but you might have to discover some
real ones before going on */
SELECT dcm.code DCM_No,
dcm.datetime_created DCM_Date,
lne.seq_number,
par.code,
par.description particular,
ft.description fee_type,
lne.amount,
case when lne.drcr =1 then 'Debit' else 'Credit' end DrCr,
case when isnull(dcm.is_sd,'N') = 'Y' then 'Salary Deduction' else null end is_sd,
org.description Company,
org.postal_address company_addr,
'S.Y. ' + substring(sy.school_year,1,4)+'-'+substring(sy.school_year,5,4) +' '+sem.description SY,
entity_a.code + ' - ' + coalesce(entity_a.stud_lname,'') +', '+coalesce(entity_a.stud_fname,'') +' '+coalesce(entity_a.stud_mname,'') Student,
case when isnull(dm.description2,'') = '' then
crs.course_short_name + '-'+convert(char(1),entity_a.stud_grade)
else crs2.course_short_name + '-'+convert(char(1),reg.stud_grade) end as Course,
isnull(dm.description2,'Not Enrolled')
FROM es.lib_rgn_students entity_a
left join ars.ars_dcm dcm on dcm.entity_id = entity_a.id
LEFT JOIN afs.entity entity_b ON dcm.prepared_by_id = entity_b.id
LEFT JOIN ua.user_account ON dcm.prepared_by_id = ua.user_account.id
left join ars.ars_dcm_line lne on lne.ars_dcm_id = dcm.id
left join es.lib_fin_fees_master par on par.id = lne.ars_particular_id
left join es.lib_fin_feetype ft on ft.code = lne.fee_code
left join es.stp_sysem sy on sy.id = dcm.period_id
inner join es.stp_semesterms sem on sem.code = sy.semester and sem.trimester = 0
inner join afs.organization org on org.id = sy.company_id
inner join es.lib_crs crs on crs.id = entity_a.course_id
left join es.trn_rgn_reg_hdr reg on reg.period = sy.id and reg.stud_id = :as_studid
left join document_status_map dm on dm.code = reg.document_status
left join es.lib_crs crs2 on crs2.id = reg.course_id
WHERE
(dcm.entity_id = @as_studid) AND -- the vars declared above are used
(dcm.period_id = @as_period) AND -- here instead of the ':'-bits
(dcm.document_status_code not in(2,3))
或者,也可以不变量来做到,只需更换:as_studid
和:as_period
用一些真实值。但是这样你就不得不记住原始查询中参数化了什么,无论如何,如果你的任务是修改查询本身,你可能必须提交它与:
-names,就像你一样收到了。
非常感谢您!! iv'e一直在寻找答案关于这个大约2天现在..我真的不知道如何处理我发生的错误..我对此没有太多的想法..我只是被分配去做这个..你救了我的生命非常感谢:D – ravenxi
如果您列确实被称为:as_studid然后用方括号括起来。 e.g.:-
WHERE
(dcm.entity_id = [:as_studid]) AND
(dcm.period_id = [:as_period]) AND
(dcm.document_status_code not in(2,3))
这应该解决这个问题
在管理工作室中运行它。双击错误消息。它向你显示'reg.stud_id =:as_studid'是问题所在。如果您尝试使用参数,那么在TSQL中有一个“@”前缀。 –
我不知道该怎么办这个问题:(我似乎有关于“:”的错误..我该怎么办?> _ ravenxi
我们应该如何知道你根据什么告诉我们?一个列的名称?如果按照Ross的回答进行分隔,它是否应该是一个参数?如果是这样,将其声明为TSQL参数并带前缀'@' –