Script Problem
-
Tuesday, February 07, 2012 2:54 PM
Hi,
The below script was working fine in a smaller scale. Now that I've made it bigger it seem to have a problem in the last part. I'm new to SQl so I'm getting lost with the whole INNER JOIN section. Please take a look and let me know if you find the problem, the error I get is that there is a problem near ON
Any help will be appreciated. Thanks.
WITH query1 AS (SELECT vo_id, voline,
STUFF((SELECT ' ' + des FROM son_db.dbo.apvodes WHERE vo_id = t.vo_id AND voline = t.voline ORDER BY dsline FOR XML PATH('')),1,1,'') AS [des]
FROM (SELECT DISTINCT vo_id,voline FROM son_db.dbo.apvodes)t)
SELECT "csddt"."ckdate" AS Date, "csddt"."cknum" AS 'Check #/GJ ID', NULL AS 'GL#',"csddt"."ckline" AS Line, "csddt"."apnum" As 'Vendor#', "ap"."apname" As 'Vendor Name', "apaddr"."appynm" As Payee, "csddt"."glnum" As 'GL Acct', "gl"."gldes" As 'GL Description', "csd"."voiddt" As 'Void Date', "csddt"."currency" As Currency, "csddt"."vo_id" As 'Voucher ID',
CASE when "csddt"."amt" > 0
then "csddt"."amt"
else 0 end AS Debit,
CASE when "csddt"."amt" < 0
then "csddt"."amt" * -1
else 0 end AS Credit,
"query1"."des" AS 'Description'
FROM ((("son_db"."dbo"."csddt" "csddt" INNER JOIN "son_db"."dbo"."csd" "csd" ON ("csddt"."cknum"="csd"."cknum") AND ("csddt"."baid"="csd"."baid")) INNER JOIN "son_db"."dbo"."apaddr" "apaddr" ON ("csddt"."apnum"="apaddr"."apnum") AND ("csddt"."apaddid"="apaddr"."apaddid")) INNER JOIN ("son_db"."dbo"."gl" "gl" ON ("csddt"."glnum"="gl"."glnum") AND ("csddt"."glrc1"="gl"."glrc1")) LEFT OUTER JOIN "son_db"."dbo"."ap" "ap" ON ("csddt"."apnum"="ap"."apnum") INNER JOIN "query1" ON ("csddt"."vo_id" = "query1"."vo_id") AND ("csddt"."ckline" = "query1"."voline")
beto81

