Click here to Skip to main content
15,914,323 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
SQL
DECLARE @previousstatus nvarchar(50)
DECLARE @presentstatus nvarchar(50)

Select @previousstatus = statu FROM ssse where ID = (Select max(id) From ssse)

IF Enddateparameter < cast(getdate() as date) then @presentstatus = 'Inactive'

IF @previousstatus = 'Inactive'
BEGIN
    Insert INTO ssse(startdate,enddate,status) VALUES(startdateparameter,enddateparameter,@presentstatus)
END




error given "Incorrect syntax near the keyword 'then'."
Posted
Comments
Timberbird 30-Oct-13 2:32am    
You don't need then here
krishna97 30-Oct-13 2:33am    
then do not used

@presentstatus = 'Inactive' error given
Timberbird 30-Oct-13 2:36am    
So in the line
IF Enddateparameter < cast(getdate() as date) then @presentstatus = 'Inactive'

then is not used?
krishna97 30-Oct-13 2:44am    
but remove this line then status Column not update automatically
Timberbird 30-Oct-13 3:05am    
I offer you to try the following:

IF Enddateparameter < cast(getdate() as date) SET @presentstatus = 'Inactive'

By the way, is it just Enddateparameter, not @Enddateparameter?

1 solution

Change your syntax to this:
DECLARE @previousstatus nvarchar(50)
DECLARE @presentstatus nvarchar(50)
 
Select @previousstatus = statu FROM ssse where ID = (Select max(id) From ssse)
 
IF Enddateparameter < cast(getdate() as date) 
Begin
    Set @presentstatus = 'Inactive'
End
 
IF @previousstatus = 'Inactive'
BEGIN
    Insert INTO ssse(startdate,enddate,status) VALUES(startdateparameter,enddateparameter,@presentstatus)
END
 
Share this answer
 
Comments
krishna97 30-Oct-13 14:50pm    
This query Not given Proper Out Put
Richard C Bishop 30-Oct-13 14:51pm    
Ok, but are there any errors?
krishna97 30-Oct-13 14:57pm    
no any error given

but my question is
USE [ddrr]
GO

/****** Object: Table [dbo].[Temp] Script Date: 10/31/2013 00:22:41 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Temp](
[Id] [int] IDENTITY(1,1) NOT NULL,
[StartDte] [date] NULL,
[Enddate] [date] NULL,
[Statu] [nvarchar](50) NULL,
CONSTRAINT [PK_ssse] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO


1- Insert query First time data can insert then second data insert then check the Status Column Inactive or Active Status Column can Inactive then Second Data can insert
2- Status Column can Update Automatically for endate can less then getdate

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900