SQL Server stored procedure

I am tring to create my first stored procedure for SQL server 2005.  I looked at some samples and came up with what I thought would be the correct syntax.  I keep geeting errors trying to run it says error line 7 near ( ). which means nothing to me.  Can anyone help?   I can use the getdate function in SQLServer trying to select and it works.
CREATE PROCEDURE dbo.spHits_update
(@STATE char(2))
AS
IF NOT EXISTS (
	SELECT * FROM Lottery_Hits WHERE LState = @STATE and DATEDIFF(day, LDate, GETDATE()) <= 0
)
   INSERT INTO Lottery_Hits (LSTATE, LDATE, LHITS) 
		VALUES (@STATE, getDate(), 1)
ELSE
  Update Lottery_Hits 
	SET HHits + 1
  WHERE LState = @State and DATEDIFF(day, LDate, GETDATE()) <= 0;
END
 
GO

Open in new window

edfrazierAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase AdministratorCommented:
CREATE PROCEDURE dbo.spHits_update
(@STATE char(2))
AS
set nocount on
IF NOT EXISTS (
      SELECT 1 FROM Lottery_Hits WHERE LState = @STATE and DATEDIFF(day, LDate, GETDATE()) <= 0
)
      INSERT INTO Lottery_Hits (LSTATE, LDATE, LHITS)
      SELECT @STATE, getDate(), 1
ELSE
   UPDATE Lottery_Hits
   set HHits = HHits+1
   WHERE LState = @STATE and DATEDIFF(day, LDate, GETDATE()) <= 0
GO

0
AanvikCommented:
Here you go.
CREATE PROCEDURE dbo.spHits_update
(@STATE char(2))
AS
BEGIN
IF NOT EXISTS (
        SELECT * FROM Lottery_Hits WHERE LState = @STATE and DATEDIFF(day, LDate, GETDATE()) <= 0
)
   INSERT INTO Lottery_Hits (LSTATE, LDATE, LHITS) 
                VALUES (@STATE, getDate(), 1)
ELSE
  Update Lottery_Hits 
        SET HHits = HHits + 1
		WHERE LState = @State 
		and DATEDIFF(day, LDate, GETDATE()) <= 0 
END
 
GO

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
edfrazierAuthor Commented:
Thanks, I am not sure what I was thinking...What i posted looks crazy.
0
Aneesh RetnakaranDatabase AdministratorCommented:
whats the problem with mine :)
0
AanvikCommented:
edfrazier, you should share the points between me and aneeshattingal, his solution is correct as well..

:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.