Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
cloud1414
Starting Member
6 Posts |
Posted - 2006-07-26 : 10:30:40
|
Hi everyone....i keep getting syntax error msg when i try to run my vb application which is supposed to retrieve some data. Could someone enlighten me on what is wrong with my sql statement? it shows syntax error and the codes in bold..assql = "SELECT Client.ClientNo, Client.Company, VIEW_CLIENT_DETAILS.[Group], " _& "VIEW_MRAUD.AUD, VIEW_MRAUD.AUDFees, " _& "VIEW_MRAUD.noofAUD, VIEW_MRTAX.TAX, VIEW_MRTAX.TAXFees,VIEW_MRTAX.noofTAX, VIEW_MRCSS.CSS, VIEW_MRCSS.CSSFees, VIEW_MRCSS.noofCSS,VIEW_MRSA.SA,VIEW_MRSA.SAFees, VIEW_MRSA.noofSA, " _& "dbo.VIEW_CLIENT_DETAILS.CoStatus, dbo.VIEW_CLIENT_DETAILS.ReferredBy, dbo.VIEW_CLIENT_DETAILS.RefFeePayable, " _& "dbo.VIEW_CLIENT_DETAILS.RefFeeScheme,dbo.VIEW_CLIENT_DETAILS.Name AS Contact, " _& "dbo.VIEW_ALL_EXSCV.ExAud, dbo.VIEW_ALL_EXSCV.ExTax,dbo.VIEW_ALL_EXSCV.ExSec, " _& "VIEW_AIC_PIC.Initial AS AIC, VIEW_SIC_PIC.Initial AS SIC,VIEW_TIC_PIC.Initial AS TIC, VIEW_PIC_RP.Initial AS RP,VIEW_PIC_CSP.Initial AS CSP " _& "FROM Client " _& "INNER JOIN VIEW_CLIENT_DETAILS ON Client.ClientNo =VIEW_CLIENT_DETAILS.ClientNo " _& "LEFT OUTER JOIN VIEW_ALL_EXSCV ON Client.ClientNo =VIEW_ALL_EXSCV.ClientNo " _& "LEFT OUTER JOIN VIEW_PIC_AIC ON Client.ClientNo =VIEW_PIC_AIC.ClientNo " _& "LEFT OUTER JOIN VIEW_PIC_SIC ON Client.ClientNo =VIEW_PIC_SIC.ClientNo " _& "LEFT OUTER JOIN VIEW_PIC_TIC ON Client.ClientNo =VIEW_PIC_TIC.ClientNo " _& "LEFT OUTER JOIN VIEW_PIC_CSP ON Client.ClientNo =VIEW_PIC_CSP.ClientNo " _& "LEFT OUTER JOIN VIEW_PIC_RP ON Client.ClientNo =VIEW_PIC_RP.ClientNo " _& "LEFT OUTER JOIN " _& "(SELECT ClientNo, JoinDate AS AUD, NULL AS CSS, NULL AS TAX,NULL AS SA, 0 AS noofCSS, COUNT(SvcCode) AS noofAUD, 0 AS noofTAX, 0 AS noofSA, Fee as AUDFees " _& "From VIEW_Client_SvcJoinDetail_Fees WHERE (SvcCode = 'AUD')AND (JoinDate >= '" & Format(asP(1), "yyyy-mm-dd") & "') AND (JoinDate <= '" & Format(asP(2), "yyyy-mm-dd") & "') GROUP BY ClientNo, SvcCode,Fee,JoinDate) CH_VIEW_MRAUD ON " _& "Client.ClientNo = CH_VIEW_MRAUD.ClientNo LEFT OUTER JOIN(SELECT ClientNo, NULL AS AUD, NULL AS CSS, JoinDate AS TAX, NULL AS SA, 0 AS noofCSS, 0 AS noofAUD, COUNT(SvcCode) AS noofTAX, 0 AS noofSA,Fee as TAXFees " _& "From VIEW_Client_SvcJoinDetail_Fees WHERE (SvcCode = 'TAX') AND (JoinDate >= '" & Format(asP(1), "yyyy-mm-dd") & "') AND (JoinDate <= '" & Format(asP(2), "yyyy-mm-dd") & "') GROUP BY ClientNo, SvcCode,Fee, JoinDate) CH_VIEW_MRTAX ON " _& "Client.ClientNo = CH_VIEW_MRTAX.ClientNo LEFT OUTER JOIN(SELECT ClientNo, NULL AS AUD, JoinDate AS CSS, NULL AS TAX, NULL AS SA, COUNT(SvcCode) AS noofCSS, 0 AS noofAUD, 0 AS noofTAX, 0 AS noofSA,Fee as CSSFees " _& "From VIEW_Client_SvcJoinDetail_Fees WHERE (SvcCode = 'CSS') AND (JoinDate >= '" & Format(asP(1), "yyyy-mm-dd") & "') AND (JoinDate <= '" & Format(asP(2), "yyyy-mm-dd") & "') GROUP BY ClientNo, SvcCode,Fee,JoinDate) CH_VIEW_MRCSS ON " _& "Client.ClientNo = CH_VIEW_MRCSS.ClientNo LEFT OUTER JOIN(SELECT ClientNo, NULL AS AUD, NULL AS CSS, NULL AS TAX, JoinDate AS SA, 0 AS noofCSS, 0 AS noofAUD, COUNT(SvcCode) AS noofSA, 0 AS noofTAX, Fee as SAFees " _& "From VIEW_Client_SvcJoinDetail_Fees WHERE (SvcCode = 'SA')AND (JoinDate >= '" & Format(asP(1), "yyyy-mm-dd") & "') AND (JoinDate <= '" & Format(asP(2), "yyyy-mm-dd") & "') GROUP BY ClientNo, SvcCode,Fee,JoinDate) CH_VIEW_MRSA ON " _& "Client.ClientNo = CH_VIEW_MRSA.ClientNo whereCH_view_mraud.aud is not null or CH_view_mrtax.tax is not null orCH_view_mrcss.css is not null or CH_view_mrsa.sa is not null order byClient.clientno" |
|
Kristen
Test
22859 Posts |
Posted - 2006-07-26 : 10:50:53
|
[code]& "LEFT OUTER JOIN " _& "(SELECT ClientNo, JoinDate AS AUD, NULL AS CSS, NULL AS ^^----------[/code]Assuming there is NO line break in there, as you have shown it, I reckon that's the problem.How you can hope to debug your code with such dreadful formatting is beyond my ken.You should use YYYYMMDD style string dates, and no YYYY-MM-DDI can't work out why you have OUTER JOINS and then an IS NOT NULL test in your WHERE clauseOr why your nested sub-selects are including dummy columns with dummy values which are unreferenced.Unless you have only a handful of records I reckon this query will run like a dog!Here's how I formatted your code so I had a chance of seeing what was going on[code]SELECT Client.ClientNo, Client.Company, VIEW_CLIENT_DETAILS.[Group], VIEW_MRAUD.AUD, VIEW_MRAUD.AUDFees, VIEW_MRAUD.noofAUD, VIEW_MRTAX.TAX, VIEW_MRTAX.TAXFees, VIEW_MRTAX.noofTAX, VIEW_MRCSS.CSS, VIEW_MRCSS.CSSFees, VIEW_MRCSS.noofCSS, VIEW_MRSA.SA, VIEW_MRSA.SAFees, VIEW_MRSA.noofSA, dbo.VIEW_CLIENT_DETAILS.CoStatus, dbo.VIEW_CLIENT_DETAILS.ReferredBy, dbo.VIEW_CLIENT_DETAILS.RefFeePayable, dbo.VIEW_CLIENT_DETAILS.RefFeeScheme, dbo.VIEW_CLIENT_DETAILS.Name AS Contact, dbo.VIEW_ALL_EXSCV.ExAud, dbo.VIEW_ALL_EXSCV.ExTax, dbo.VIEW_ALL_EXSCV.ExSec, VIEW_AIC_PIC.Initial AS AIC, VIEW_SIC_PIC.Initial AS SIC, VIEW_TIC_PIC.Initial AS TIC, VIEW_PIC_RP.Initial AS RP, VIEW_PIC_CSP.Initial AS CSP FROM Client INNER JOIN VIEW_CLIENT_DETAILS ON Client.ClientNo = VIEW_CLIENT_DETAILS.ClientNo LEFT OUTER JOIN VIEW_ALL_EXSCV ON Client.ClientNo = VIEW_ALL_EXSCV.ClientNo LEFT OUTER JOIN VIEW_PIC_AIC ON Client.ClientNo = VIEW_PIC_AIC.ClientNo LEFT OUTER JOIN VIEW_PIC_SIC ON Client.ClientNo = VIEW_PIC_SIC.ClientNo LEFT OUTER JOIN VIEW_PIC_TIC ON Client.ClientNo = VIEW_PIC_TIC.ClientNo LEFT OUTER JOIN VIEW_PIC_CSP ON Client.ClientNo = VIEW_PIC_CSP.ClientNo LEFT OUTER JOIN VIEW_PIC_RP ON Client.ClientNo = VIEW_PIC_RP.ClientNo LEFT OUTER JOIN ( SELECT ClientNo, JoinDate AS AUD, NULL AS CSS, NULL AS TAX, NULL AS SA, 0 AS noofCSS, COUNT(SvcCode) AS noofAUD, 0 AS noofTAX, 0 AS noofSA, Fee as AUDFees From VIEW_Client_SvcJoinDetail_Fees WHERE (SvcCode = 'AUD') AND (JoinDate >= '" & Format(asP(1), "yyyy-mm-dd") & "') AND (JoinDate <= '" & Format(asP(2), "yyyy-mm-dd") & "') GROUP BY ClientNo, SvcCode, Fee, JoinDate ) CH_VIEW_MRAUD ON Client.ClientNo = CH_VIEW_MRAUD.ClientNo LEFT OUTER JOIN ( SELECT ClientNo, NULL AS AUD, NULL AS CSS, JoinDate AS TAX, NULL AS SA, 0 AS noofCSS, 0 AS noofAUD, COUNT(SvcCode) AS noofTAX, 0 AS noofSA, Fee as TAXFees From VIEW_Client_SvcJoinDetail_Fees WHERE (SvcCode = 'TAX') AND (JoinDate >= '" & Format(asP(1), "yyyy-mm-dd") & "') AND (JoinDate <= '" & Format(asP(2), "yyyy-mm-dd") & "') GROUP BY ClientNo, SvcCode,Fee, JoinDate ) CH_VIEW_MRTAX ON Client.ClientNo = CH_VIEW_MRTAX.ClientNo LEFT OUTER JOIN ( SELECT ClientNo, NULL AS AUD, JoinDate AS CSS, NULL AS TAX, NULL AS SA, COUNT(SvcCode) AS noofCSS, 0 AS noofAUD, 0 AS noofTAX, 0 AS noofSA,Fee as CSSFees From VIEW_Client_SvcJoinDetail_Fees WHERE (SvcCode = 'CSS') AND (JoinDate >= '" & Format(asP(1), "yyyy-mm-dd") & "') AND (JoinDate <= '" & Format(asP(2), "yyyy-mm-dd") & "') GROUP BY ClientNo, SvcCode,Fee,JoinDate ) CH_VIEW_MRCSS ON Client.ClientNo = CH_VIEW_MRCSS.ClientNo LEFT OUTER JOIN ( SELECT ClientNo, NULL AS AUD, NULL AS CSS, NULL AS TAX, JoinDate AS SA, 0 AS noofCSS, 0 AS noofAUD, COUNT(SvcCode) AS noofSA, 0 AS noofTAX, Fee as SAFees From VIEW_Client_SvcJoinDetail_Fees WHERE (SvcCode = 'SA') AND (JoinDate >= '" & Format(asP(1), "yyyy-mm-dd") & "') AND (JoinDate <= '" & Format(asP(2), "yyyy-mm-dd") & "') GROUP BY ClientNo, SvcCode,Fee,JoinDate ) CH_VIEW_MRSA ON Client.ClientNo = CH_VIEW_MRSA.ClientNo where CH_view_mraud.aud is not null or CH_view_mrtax.tax is not null or CH_view_mrcss.css is not null or CH_view_mrsa.sa is not null order by Client.clientno[/code]Kristen |
|
|
cloud1414
Starting Member
6 Posts |
Posted - 2006-07-26 : 21:12:00
|
Hi Kristen,There is a line break there. And i have changed the YYYYMMDD style string dates...but i still have the same error...where else have i gone wrong?cloudquote: Originally posted by Kristen
& "LEFT OUTER JOIN " _& "(SELECT ClientNo, JoinDate AS AUD, NULL AS CSS, NULL AS ^^---------- Assuming there is NO line break in there, as you have shown it, I reckon that's the problem.How you can hope to debug your code with such dreadful formatting is beyond my ken.You should use YYYYMMDD style string dates, and no YYYY-MM-DDI can't work out why you have OUTER JOINS and then an IS NOT NULL test in your WHERE clauseOr why your nested sub-selects are including dummy columns with dummy values which are unreferenced.Unless you have only a handful of records I reckon this query will run like a dog!Here's how I formatted your code so I had a chance of seeing what was going onSELECT Client.ClientNo, Client.Company, VIEW_CLIENT_DETAILS.[Group], VIEW_MRAUD.AUD, VIEW_MRAUD.AUDFees, VIEW_MRAUD.noofAUD, VIEW_MRTAX.TAX, VIEW_MRTAX.TAXFees, VIEW_MRTAX.noofTAX, VIEW_MRCSS.CSS, VIEW_MRCSS.CSSFees, VIEW_MRCSS.noofCSS, VIEW_MRSA.SA, VIEW_MRSA.SAFees, VIEW_MRSA.noofSA, dbo.VIEW_CLIENT_DETAILS.CoStatus, dbo.VIEW_CLIENT_DETAILS.ReferredBy, dbo.VIEW_CLIENT_DETAILS.RefFeePayable, dbo.VIEW_CLIENT_DETAILS.RefFeeScheme, dbo.VIEW_CLIENT_DETAILS.Name AS Contact, dbo.VIEW_ALL_EXSCV.ExAud, dbo.VIEW_ALL_EXSCV.ExTax, dbo.VIEW_ALL_EXSCV.ExSec, VIEW_AIC_PIC.Initial AS AIC, VIEW_SIC_PIC.Initial AS SIC, VIEW_TIC_PIC.Initial AS TIC, VIEW_PIC_RP.Initial AS RP, VIEW_PIC_CSP.Initial AS CSP FROM Client INNER JOIN VIEW_CLIENT_DETAILS ON Client.ClientNo = VIEW_CLIENT_DETAILS.ClientNo LEFT OUTER JOIN VIEW_ALL_EXSCV ON Client.ClientNo = VIEW_ALL_EXSCV.ClientNo LEFT OUTER JOIN VIEW_PIC_AIC ON Client.ClientNo = VIEW_PIC_AIC.ClientNo LEFT OUTER JOIN VIEW_PIC_SIC ON Client.ClientNo = VIEW_PIC_SIC.ClientNo LEFT OUTER JOIN VIEW_PIC_TIC ON Client.ClientNo = VIEW_PIC_TIC.ClientNo LEFT OUTER JOIN VIEW_PIC_CSP ON Client.ClientNo = VIEW_PIC_CSP.ClientNo LEFT OUTER JOIN VIEW_PIC_RP ON Client.ClientNo = VIEW_PIC_RP.ClientNo LEFT OUTER JOIN ( SELECT ClientNo, JoinDate AS AUD, NULL AS CSS, NULL AS TAX, NULL AS SA, 0 AS noofCSS, COUNT(SvcCode) AS noofAUD, 0 AS noofTAX, 0 AS noofSA, Fee as AUDFees From VIEW_Client_SvcJoinDetail_Fees WHERE (SvcCode = 'AUD') AND (JoinDate >= '" & Format(asP(1), "yyyy-mm-dd") & "') AND (JoinDate <= '" & Format(asP(2), "yyyy-mm-dd") & "') GROUP BY ClientNo, SvcCode, Fee, JoinDate ) CH_VIEW_MRAUD ON Client.ClientNo = CH_VIEW_MRAUD.ClientNo LEFT OUTER JOIN ( SELECT ClientNo, NULL AS AUD, NULL AS CSS, JoinDate AS TAX, NULL AS SA, 0 AS noofCSS, 0 AS noofAUD, COUNT(SvcCode) AS noofTAX, 0 AS noofSA, Fee as TAXFees From VIEW_Client_SvcJoinDetail_Fees WHERE (SvcCode = 'TAX') AND (JoinDate >= '" & Format(asP(1), "yyyy-mm-dd") & "') AND (JoinDate <= '" & Format(asP(2), "yyyy-mm-dd") & "') GROUP BY ClientNo, SvcCode,Fee, JoinDate ) CH_VIEW_MRTAX ON Client.ClientNo = CH_VIEW_MRTAX.ClientNo LEFT OUTER JOIN ( SELECT ClientNo, NULL AS AUD, JoinDate AS CSS, NULL AS TAX, NULL AS SA, COUNT(SvcCode) AS noofCSS, 0 AS noofAUD, 0 AS noofTAX, 0 AS noofSA,Fee as CSSFees From VIEW_Client_SvcJoinDetail_Fees WHERE (SvcCode = 'CSS') AND (JoinDate >= '" & Format(asP(1), "yyyy-mm-dd") & "') AND (JoinDate <= '" & Format(asP(2), "yyyy-mm-dd") & "') GROUP BY ClientNo, SvcCode,Fee,JoinDate ) CH_VIEW_MRCSS ON Client.ClientNo = CH_VIEW_MRCSS.ClientNo LEFT OUTER JOIN ( SELECT ClientNo, NULL AS AUD, NULL AS CSS, NULL AS TAX, JoinDate AS SA, 0 AS noofCSS, 0 AS noofAUD, COUNT(SvcCode) AS noofSA, 0 AS noofTAX, Fee as SAFees From VIEW_Client_SvcJoinDetail_Fees WHERE (SvcCode = 'SA') AND (JoinDate >= '" & Format(asP(1), "yyyy-mm-dd") & "') AND (JoinDate <= '" & Format(asP(2), "yyyy-mm-dd") & "') GROUP BY ClientNo, SvcCode,Fee,JoinDate ) CH_VIEW_MRSA ON Client.ClientNo = CH_VIEW_MRSA.ClientNo where CH_view_mraud.aud is not null or CH_view_mrtax.tax is not null or CH_view_mrcss.css is not null or CH_view_mrsa.sa is not null order by Client.clientno Kristen
|
|
|
Kristen
Test
22859 Posts |
Posted - 2006-07-27 : 05:26:16
|
I presume we are taking about a VB syntax error, and not a SQL Syntax error - i.e. an error reported back by the server?If its from the server knowing the exact error message may help.(Either way I didn't see any, but its a big bit of script)Kristen |
|
|
cloud1414
Starting Member
6 Posts |
Posted - 2006-07-27 : 09:56:47
|
I have tried the codes on query analyzer and it works....so i guess it's a VB syntax error...cloudquote: Originally posted by Kristen I presume we are taking about a VB syntax error, and not a SQL Syntax error - i.e. an error reported back by the server?If its from the server knowing the exact error message may help.(Either way I didn't see any, but its a big bit of script)Kristen
|
|
|
Kristen
Test
22859 Posts |
Posted - 2006-07-27 : 10:15:15
|
I stuck it in my colour coding editor, and it loks fine in there. But the linebreaks in what you posted are wrong, so I'm assuming that you have genuinely got linebreaks after each trailing _So you have a Programmers Editor with Regular Expression Find tool?If so put the cursor at the start of theassql = "SELECT bit and do a FIND for[^_]$and check that the first thing it finds is the very final double-quote. Otherwise you have a line which does NOT end in "_"Kristen |
|
|
cloud1414
Starting Member
6 Posts |
Posted - 2006-07-27 : 10:23:18
|
I'm actually using microsoft visual studio 6.0....would it have the Regular expression find tool? do u know where i can find that?I'm pretty sure my line break is right...I accidentally posted it wrongly here...but the actual code i correct...cloudquote: Originally posted by Kristen I stuck it in my colour coding editor, and it loks fine in there. But the linebreaks in what you posted are wrong, so I'm assuming that you have genuinely got linebreaks after each trailing _So you have a Programmers Editor with Regular Expression Find tool?If so put the cursor at the start of theassql = "SELECT bit and do a FIND for[^_]$and check that the first thing it finds is the very final double-quote. Otherwise you have a line which does NOT end in "_"Kristen
|
|
|
Kristen
Test
22859 Posts |
Posted - 2006-07-27 : 10:32:01
|
Don't know about Visual Studio I'm afraid.Check you haven't got a trailing space after end of the "_" - can you move the cursor to the right of the "_" ??Maybe delete ALL the "_" so that the whole statement is on one line, as an experiment.Maybe the error is elsewhere, and that's just where the parser thought the error was?Cut&Paste that section of code to a single stand-alone function and see if you still get a syntax error? (Its only a string assignment, so it doesn't need anything else, other than the asP array.)Kristen |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2006-07-28 : 03:11:16
|
what's the syntax error? vb should be able to point out the line numberyou could also improve debugging by creating a stored procedure instead of creating the query like that --------------------keeping it simple... |
|
|
cloud1414
Starting Member
6 Posts |
Posted - 2006-07-28 : 10:02:46
|
It never say what's the syntax error... only says syntax error and the codes in bold in the error msg...i'm actually editing a program handover from the previous personnel...so i didn't wish to change too much... quote: Originally posted by jen what's the syntax error? vb should be able to point out the line numberyou could also improve debugging by creating a stored procedure instead of creating the query like that --------------------keeping it simple...
|
|
|
cloud1414
Starting Member
6 Posts |
Posted - 2006-07-28 : 11:43:58
|
i can't use stored procedure as the statement is dynamic...the "joindate" is going to be entered in by the user...not fixed...quote: Originally posted by jen what's the syntax error? vb should be able to point out the line numberyou could also improve debugging by creating a stored procedure instead of creating the query like that --------------------keeping it simple...
|
|
|
Kristen
Test
22859 Posts |
Posted - 2006-07-29 : 04:20:39
|
No problem at all having a parameter in a stored procedure.If you mean the column name is also dynamic then there are several ways of doing that in a Stored Procedure too.Kristen |
|
|
|
|
|
|
|