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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Procedure not executing

Author  Topic 

mayoorsubbu
Yak Posting Veteran

95 Posts

Posted - 2010-07-12 : 09:43:39
Hi Gurus,

I have created a simple SP to insert records into a table. The table also calls a function to generate an ID (PK). While the procedure has been created without any trouble, it throws an error on being called.

create procedure InsertRequestMaster
@cUnit nchar(10),
@cRequestno nchar(75) = '30 WG/LGS/1234/GIFTING',
@dRequestDt datetime ,
@dRecdDt datetime ,
@dRegnDate datetime ,
@cRemarks varchar(100) = NULL
--@cRequestType nchar (4),
--@nAfQty int,
--@nAeQty int
AS
BEGIN
DECLARE @cNextId char(8)
BEGIN TRANSACTION;
-- Store nextId in a variable
--SELECT @dRequestDt = GETDATE()
--SELECT @dRecdDt = GETDATE()
--SELECT @dRegnDate = GETDATE()
SELECT @cNextId= DBO.GETID(GETDATE())
INSERT INTO RequestMaster ( RequestId, Unit, RequestNo, RequestDt, RecdDt, RegnDt, Remarks)
VALUES (@cNextId, @cRequestno, @cUnit, @dRequestDt, @dRecdDt, @dRegnDate, @cRemarks);
UPDATE IdMaster set LastId = @cNextId
COMMIT TRANSACTION;
END



I call it like so

EXEC InsertRequestMaster @cUnit='30 WG', 
@dRequestDt=getdate(),
@dRecdDt=getdate(),
@dRegnDate=getdate()


The error is

quote:
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ')'.


Help.

Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-12 : 10:37:46
Try:
declare @rq datetime, @rc datetime, @rg dateime
set @rq=getdate()
set @rc=getdate()
set @rg=getdate()
EXEC InsertRequestMaster @cUnit='30 WG',
@dRequestDt=@rq,
@dRecdDt=@rc,
@dRegnDate=@rg



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2010-07-12 : 15:20:24
You can do it as above i.e named parameters , or you could use positional parameters,but you can't make the "getdate()" function call in the list of parameters

declare @dat1 datetime , @dat2 datetime, @dat3 datetime,@cUnit varchar(30)
set @dat1 = getdate()
set @dat2 = getdate()
set @dat3 = getdate()
set @cUnit = ''30 WG'

EXEC InsertRequestMaster @cUnit,@dat1,@dat2,@dat3

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page
   

- Advertisement -