syntax help

M

Mangler

I created a query in SQL that works fine but when i put it in the asp
code ( with dreamweaver ) i am getting an error when viewing the
page: expected end of statment...

rsBERProd_cmd.CommandText = "SELECT ISNULL(sum(case when type = 'BD'
and _dte = Convert(Char(8),GETDATE(),112) then qty else 0 end),0) as
Dayqty,ISNULL(sum(case when type = 'BD' and _dte between dateadd(dd,-
(day(GetDate())-1),GetDate()) and dateadd(dd,-(day(dateadd(mm,
1,GetDate()))),dateadd(mm,1,GetDate())) then qty else 0 end),0) as
Monthqty,ISNULL(sum(case when type = 'BD' and Year(_dte) =
Year(GetDate()) then qty else 0 end),0) as Yearqty,ISNULL(sum(case
when type = 'BD' and DatePart("ww", _dte)=DatePart("ww",
GetDate()) then qty else 0 end),0) as weekqty FROM
dbo.warehousebertransfer"

the problem i know is here: ("ww", _dte)=DatePart("ww",
GetDate())

the query needs those quotes so how can i get this to work? i tried
using just single quotes but then i get a sql error.... so can someone
help me make this work on the page?
 
M

Mangler

I created a query in SQL that works fine but when i put it in the asp
code ( with dreamweaver ) i am getting an error when viewing the
page: expected end of statment...

rsBERProd_cmd.CommandText = "SELECT ISNULL(sum(case when type = 'BD'
and _dte = Convert(Char(8),GETDATE(),112) then qty else 0 end),0) as
Dayqty,ISNULL(sum(case when type = 'BD' and _dte between dateadd(dd,-
(day(GetDate())-1),GetDate()) and dateadd(dd,-(day(dateadd(mm,
1,GetDate()))),dateadd(mm,1,GetDate())) then qty else 0 end),0) as
Monthqty,ISNULL(sum(case when type = 'BD' and Year(_dte) =
Year(GetDate()) then qty else 0 end),0) as Yearqty,ISNULL(sum(case
when type = 'BD' and DatePart("ww", _dte)=DatePart("ww",
GetDate()) then qty else 0 end),0) as weekqty FROM
dbo.warehousebertransfer"

the problem i know is here: ("ww", _dte)=DatePart("ww",
GetDate())

the query needs those quotes so how can i get this to work? i tried
using just single quotes but then i get a sql error.... so can someone
help me make this work on the page?

nevermind, i just figured it out :)

DatePart(" & """ww"", _dte)=DatePart(" & """ww"", GetDate())
 
B

Bob Barrows [MVP]

Mangler said:
nevermind, i just figured it out :)

DatePart(" & """ww"", _dte)=DatePart(" & """ww"", GetDate())

That works?? Given the use of GETDATE and ISNULL, this looks like T-SQL.
Unlike the VB/VBA/vbscript versions of the DATEPART,DATEADD and DATEDIFF
functions, T-SQL does not permit the use of quotes around the datepart
argument. It should simply be:

DatePart(ww, _dte)=DatePart(ww, GetDate())

See earlier in your sql statement where you used the dateadd function?
Same idea.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top