Welcome Guest ( Log In | Register )


Bump Topic Add Reply RSS Feed New Topic New Poll

Outline · [ Standard ] · Linear+

> Got stuck in learning SQL, Please help to contribute idea (SQL)

views
     
TSk town shit
post Mar 29 2019, 02:04 PM, updated 2 months ago

Casual
***
Group: Junior Member
Posts: 348

Joined: Jan 2009
Hi Guru, I got hit by an error when executing the codes,

These are my SQL script:
CODE
DECLARE @datefrom INT,
@fromitemno VARCHAR (20),
@ITEMNO VARCHAR (20),
@ACCTSET VARCHAR(50),
@LOCATION VARCHAR(50)

GO

SET @DATEFROM = '20180101',
@FROMITEMNO = 'FBOP101000',
@TOITEMNO = 'FBOP101000',
@ACCTSET = 'FG',
@LOCATION = 'BCPF'

GO

select case when TRANSDATE is null or TRANSDATE < @DATEFROM then 0 else isnull (ichist.quantity * icunit.conversion, 0) end
QtyStkUomAfterDateFrom, ichist.TRANSDATE, iciloc.[LOCATION], docnum, ichist.homeextcst, ICILOC.TOTALCOST, ICILOC.QTYONHAND, ICITEM.FMTITEMNO, ICITEM.[DESC] ICITEMDESC,
ichist.QUANTITY, ICUNIT.CONVERSION, ICHIST.UNIT, ICILOC.ITEMNO, ICITEM.STOCKUNIT, ICHIST.APP, ICHIST.TRANSTYPE, ICACCT.CNTLACCT, ICACCT.[DESC], ICILOC.STDCOST, ICHIST.FISCPERIOD,
ICHIST.FISCYEAR, ICITEM.COMMODIM, ICITEM.UNITWGT, ICILOC.QTYONHAND * ICITEM.UNITWGT AS totalQtyInKG

FROM

ICILOC
LEFT OUTER JOIN ICITEM ON ICILOC.ITEMNO = ICITEM.ITEMNO
LEFT OUTER JOIN ICHIST ON (ICILOC.LOCATION = ICHIST.LOCATION) AND (ICILOC.ITEMNO = ICHIST.ITEMNO)
LEFT OUTER JOIN ICUNIT ON (ICHIST.ITEMNO = ICUNIT.ITEMNO) AND (ICHIST.UNIT = ICUNIT.UNIT)
LEFT OUTER JOIN ICACCT ON ICITEM.CNTLACCT = ICACCT.CNTLACCT
WHERE (ICILOC.ITEMNO >= @FROMITEMNO AND ICILOC.ITEMNO <= @TOITEMNO)
AND ICITEM.CNTLACCT LIKE @ACCTSET
AND ICILOC.[LOCATION] LIKE @LOCATION
AND ICITEM.COMMODIM <> ''



These are the errors I hit:
QUOTE
Msg 137, Level 15, State 1, Line 9
Must declare the scalar variable "@DATEFROM".
Msg 137, Level 15, State 2, Line 17
Must declare the scalar variable "@DATEFROM".
Msg 102, Level 15, State 1, Line 18
Incorrect syntax near 'QtyStkUomAfterDateFrom'.


Does anybody has any idea where is the part that gone wrong? I'm new to SQL, been stuck in this two days icon_question.gif
hoilok
post Mar 29 2019, 02:10 PM

Regular
******
Group: Senior Member
Posts: 1,124

Joined: Apr 2007



DECLARE lah @DATEFROM
!!!!!!



DECLARE @datefrom INT,
@fromitemno VARCHAR (20),
@ITEMNO VARCHAR (20),
@ACCTSET VARCHAR(50),
@LOCATION VARCHAR(50)

GO


WHERE is the variable ??????

This post has been edited by hoilok: Mar 29 2019, 02:10 PM
TSk town shit
post Mar 29 2019, 02:24 PM

Casual
***
Group: Junior Member
Posts: 348

Joined: Jan 2009
QUOTE(hoilok @ Mar 29 2019, 01:10 PM)
DECLARE lah @DATEFROM
!!!!!!
DECLARE @datefrom INT,
@fromitemno VARCHAR (20),
@ITEMNO VARCHAR (20),
@ACCTSET VARCHAR(50),
@LOCATION VARCHAR(50)

GO
WHERE is the variable ??????
*
I know whats wrong already, typo error, thanks
Pain4UrsinZ
post Mar 29 2019, 02:30 PM

Regular
******
Group: Senior Member
Posts: 1,208

Joined: Dec 2008
From: In The HELL FIRE




@ITEMNO VARCHAR (20)

i dont know

This post has been edited by Pain4UrsinZ: Mar 29 2019, 02:30 PM
TSk town shit
post Mar 29 2019, 03:39 PM

Casual
***
Group: Junior Member
Posts: 348

Joined: Jan 2009
QUOTE(Pain4UrsinZ @ Mar 29 2019, 01:30 PM)
@ITEMNO VARCHAR (20)

i dont know
*
Yes, you are right, sorry, my mistake.
turnmoil
post Apr 3 2019, 10:45 AM

Casual
***
Group: Junior Member
Posts: 363

Joined: Jan 2003
From: The Miau Miaw Niau Miow Land


be careful.. typo mistake quite costly in real world development work



Bump Topic Add ReplyOptions New Topic
 

Switch to:
| Lo-Fi Version
0.0426sec    1.78    5 queries    GZIP Disabled
Time is now: 25th May 2019 - 12:00 PM