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
 please help me in procedure

Author  Topic 

vedjha
Posting Yak Master

228 Posts

Posted - 2009-10-28 : 19:35:10
Hello,
I have a procedure .
ie,


=========================



create proc [prcAllocateScratch] @sid varchar(9), @packid varchar(9),@totalscratch int
as
begin

if exists (select count(iid) as totalScratch from scratch where vpackid=@packid and vat_id is null and vallotuser is null having count(iid)>=@totalscratch)

begin

update scratch set
vallotuser=@sid,dtreadtime=getdate(),
iincr=
(
(select top 1 (iincr) as id from scratch order by iincr desc)
+1
)
where iid in
(
select top @totalscratch iid from scratch where vpackid=@packid and vat_id is null and vallotuser is null
)

end

else

begin

print 'scratch is not avilable. please generate it...'

end

end






================


it gives me an exception as

Msg 102, Level 15, State 1, Procedure prcAllocateScratch, Line 18
Incorrect syntax near '@totalscratch'.


at query as :

select top @totalscratch iid from scratch where vpackid=@packid and vat_id is null and vallotuser is null

=================================


please help me to short out this issue

Thank you


Ved Prakash Jha

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-10-28 : 20:45:24
[code]top (@totalscratch)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

vedjha
Posting Yak Master

228 Posts

Posted - 2009-10-28 : 20:46:45
Thank you :0)

Ved Prakash Jha
Go to Top of Page
   

- Advertisement -