×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

incorrect syntax near keyword AS

incorrect syntax near keyword AS

incorrect syntax near keyword AS

(OP)
Hello all,
I have been asked to modify this query and add the vendor name to it, the only problem is that when I put it into SSMS to work with it
I get the error of incorrect sytntax near the keyword as and when I take out ass I get an incorrect syntax near the key word 'from'
any help would be great as I am fighting a sinus infection and can barely hold my head up.

CODE -->

select top 100
 i.Item,
 i.Description,
 i.SPC,
 (select isnull(sum(invl.Quantity), 0) from ARInvoiceLine invl
  where invl.Item = i.Item and invl.DateAdded >= '01/01/2014' and invl.DateAdded <'12/30/2016'
  +
  (select isnull(sum(invlc.Quantity), 0) from ARInvoiceLineComponent invlc
   where invlc.Item = i.Item and invlc.DateAdded >= '01/01/2014' and invlc.DateAdded < '12/30/2016' as 'Qty Sold'
from IMItem i
where i.SPC like @SPC
order by 'Qty Sold' desc, i.Item 

RE: incorrect syntax near keyword AS

) is missing before the single + between the two subqueries and before "as 'Qty Sold'"

CODE

select top 100
 i.Item,
 i.Description,
 i.SPC,
 (select isnull(sum(invl.Quantity), 0) from ARInvoiceLine invl
  where invl.Item = i.Item and invl.DateAdded >= '01/01/2014' 
  and invl.DateAdded <'12/30/2016'  ) 
  +
  (select isnull(sum(invlc.Quantity), 0) from ARInvoiceLineComponent invlc
   where invlc.Item = i.Item and invlc.DateAdded >= '01/01/2014' 
   and invlc.DateAdded < '12/30/2016'  )  as 'Qty Sold'
from IMItem i
where i.SPC like @SPC
order by 'Qty Sold' desc, i.Item 

Besides, of course @SPC has to be declared and set to a value valid as a LIKE clause pattern.

Bye, Olaf.

RE: incorrect syntax near keyword AS

(OP)
Olaf thanks for the help, but I am still getting an error

CODE -->

Error executing query:
declare @SPC varchar(10)
select top 100
 i.Item,
 i.Description,
 i.SPC,
 (select isnull(sum(invl.Quantity), 0) from ARInvoiceLine invl
  where (invl.Item = i.Item and invl.DateAdded >= '01/01/2014' 
  and invl.DateAdded <'12/30/2016'  ) ) +
  (select isnull(sum(invlc.Quantity), 0) from ARInvoiceLineComponent invlc
   where invlc.Item = i.Item and invlc.DateAdded >= '01/01/2014' 
   and invlc.DateAdded < '12/30/2016'  )  as 'Qty Sold'
from IMItem i
if len(rtrim(@SPC))= 0 set @SPC = '%'
where i.SPC like @SPC
order by 'Qty Sold' desc, i.Item 
Message:
Incorrect syntax near the keyword 'where'.
Error executing query:
declare @SPC varchar(10)
select top 100
 i.Item,
 i.Description,
 i.SPC,
 (select isnull(sum(invl.Quantity), 0) from ARInvoiceLine invl
  where (invl.Item = i.Item and invl.DateAdded >= '01/01/2014' 
  and invl.DateAdded <'12/30/2016'  ) ) +
  (select isnull(sum(invlc.Quantity), 0) from ARInvoiceLineComponent invlc
   where invlc.Item = i.Item and invlc.DateAdded >= '01/01/2014' 
   and invlc.DateAdded < '12/30/2016'  )  as 'Qty Sold'
from IMItem i
if len(rtrim(@SPC))= 0 set @SPC = '%'
where i.SPC like @SPC
order by 'Qty Sold' desc, i.Item 
Message:
Incorrect syntax near the keyword 'where'.

Thanks! 

RE: incorrect syntax near keyword AS

You can't put an IF statement in the middle of a query. Try using CASE in the WHERE clause instead.

Tamar

RE: incorrect syntax near keyword AS

(OP)
hello all,
sorry
i have not gotten back to you and thanks for all the help. all the suggestions have not helped and i have not gotten back as i have been at the doctor all week.found out that my headache was not a sinus infection,, it is a huge brain tumor.i am going in for in for emergency surgery in the morning and will get back to it as soon as i can. i am supposed to be in ICU for a couple of days and we will see from there. thanks again all of you1

RE: incorrect syntax near keyword AS

Best wishes!

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom

RE: incorrect syntax near keyword AS

Sad news, I hope this ends good for you, all the best wishes.

Bye, Olaf.

RE: incorrect syntax near keyword AS

Sending wishes for a speedy and full recovery.

Tamar

RE: incorrect syntax near keyword AS

(OP)
Hello everyone!
got out of the hospital on Sunday and it looks like I will have some challenges, but at least my thinking seems too have cleared up some and I figured out the problem.

Thanks for all the help and good wishs!

RE: incorrect syntax near keyword AS

Glad you are ok

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close