Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 19th, 2004, 01:00 PM
chaleepas chaleepas is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 chaleepas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
new to microsoft sql/asp and having syntax issue-HELP??

Hi everyone, I am new to using microsoft version of sql and having issues with some syntax. The
sql statment was created by someone else and it seems that ever since IE was updated (or mysql server updates), we have had a broken statement. I have tried to fix it without much success, the first error was "Incorrect syntax near the keyword UNION". It appeared that I had that issue resolved and then started getting an "error converting varchar to data type" message. Can someone take a look at the code? "sCountIN" is a variable number... I would appreciate it very much... thank you. (Syntax I found about variables say to use only double quotes if it is a number, but if I take the single quotes out, I get the syntax error near keyword UNION...


sSql = "SELECT custcount AS 'Count', CustNumber AS 'ID', 0 AS 'Amount', "

sSql = sSql & "CustomerName AS 'Name', 'cust' AS 'Type' FROM Customers "

sSql = sSql & "WHERE CustParentCustID = '" & sCountIn & "' "

sSql = sSql & "UNION SELECT d.dedcount AS 'Count', d.dedid AS 'ID', ISNULL(d.DedAmount,0) AS Amount, "

sSql = sSql & "a.Action_Type + '/' + a.Action_Reason AS Name, 'ded' AS 'Type' "

sSql = sSql & "FROM deductions d, Action_Profiles a "

sSql = sSql & "WHERE d.DedCustCount = '" & sCountIn & "' AND d.deduserstatus = 259 AND "

sSql = sSql & "a.ActionCount_key = d.dedtype "

Last edited by chaleepas : April 19th, 2004 at 01:08 PM.

Reply With Quote
  #2  
Old April 21st, 2004, 02:35 PM
blicci's Avatar
blicci blicci is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Philly
Posts: 351 blicci User rank is Sergeant Major (2000 - 5000 Reputation Level)blicci User rank is Sergeant Major (2000 - 5000 Reputation Level)blicci User rank is Sergeant Major (2000 - 5000 Reputation Level)blicci User rank is Sergeant Major (2000 - 5000 Reputation Level)blicci User rank is Sergeant Major (2000 - 5000 Reputation Level)blicci User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 22 h 8 m 5 sec
Reputation Power: 52
I've never used mysql, does it support the use of stored procedures? If so you may be better off using those instead of building a string value for the sql statement. They are alot easier to trouble shoot and since they are compiled, they run faster. Did you try executing the query outside of your app, directly against the database to see if you get the same error. As far as i can tell your syntax is correct. Mabey there is a problem with the variable you are passing as sCountIn. Instead of executing the query, response.write it out to your page and see what it looks like. Copy and past it into your query analyzer and see if it works.

Reply With Quote
  #3  
Old April 21st, 2004, 02:39 PM
blicci's Avatar
blicci blicci is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Philly
Posts: 351 blicci User rank is Sergeant Major (2000 - 5000 Reputation Level)blicci User rank is Sergeant Major (2000 - 5000 Reputation Level)blicci User rank is Sergeant Major (2000 - 5000 Reputation Level)blicci User rank is Sergeant Major (2000 - 5000 Reputation Level)blicci User rank is Sergeant Major (2000 - 5000 Reputation Level)blicci User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 22 h 8 m 5 sec
Reputation Power: 52
I think i figured it out. You said that if your sCountIn is a number. Do not use quotes at all. and make sure that you build an extra space before you start the union part of your query like this.
"WHERE CustParentCustID =" & sCountIn & " "

Reply With Quote
  #4  
Old September 10th, 2004, 04:33 PM
chaleepas chaleepas is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 chaleepas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile Did Not Work

HI, I am back able to work on this project. I tried the suggestion there, but it did not work. Any other Ideas? I am so new to this I wouldn't know where to begin with a stored procedure. The company we got this from, is no longer in business and I am trying to trouble shoot this myself. I only have a little sql and javascript and no vbscript experience at all. Please help?? thank you. The sCountIn has been set back to just the " & sCountIn & " for both sides of the Union, cause I found several place telling me if it's a number do not put the single quotes in. So now, I have to figure out what is going on with my UNION syntax... anyone?? thank you so much...

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > new to microsoft sql/asp and having syntax issue-HELP??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway