13,298,361 members (55,390 online)
Rate this:
See more:
```insert into datef
( id , date1 , date2 , name1 )
values
( 1 ,  getdate() , select max(date1)+ 1 from  datef  else 'insert 1st Jan <Current year>' , 'name1')```

How can i use the above statment in normal query

OP's additional information moved from non-solution below
I am getting error in this statement while executing pls sort it out
`select max(date1)+ 1 from datef else 'insert 1st Jan '`
Posted 17-Nov-12 1:07am
lalitkr1.9K
Updated 17-Nov-12 2:40am
Nelek142.3K
v3
OriginalGriff 17-Nov-12 6:28am

This is not a good question - we cannot work out from that little what you are trying to do.
That is a normal query, so what are you trying to do that you haven't explained?
Use the "Improve question" widget to edit your question and provide better information.

Rate this:

## Solution 2

If `date1` is `NULL` then `MAX(date1)` is always `NULL`. You need to use `COALESCE `function to get non-nullable value. For example:
```DECLARE @curdate AS DATETIME

SET @curdate = GETDATE()

SELECT MAX(COALESCE(date1, @curdate)+ 1
FROM YOUR_TABLE_NAME```

Depending on MS SQL Server use date and time function[^] corresponding to your needs.
Rate this:

## Solution 3

```Declare @date As datetime

Select @date=MAX(date1) From datef

If(@date Is Null) Set @date=Convert(datetime, '01-Jan-'+DateName(yyyy,GetDate()))

insert into datef
( id , date1 , date2 , name1 )
values
( 1 ,  getdate() , @date , 'name1')
```

Top Experts
Last 24hrsThis month
 ppolymorphe 190 Dave Kreskowiak 130 OriginalGriff 125 JustWatchLittle 100 Richard MacCutchan 90
 OriginalGriff 2,354 Jochen Arndt 1,255 Richard MacCutchan 1,215 ppolymorphe 1,162 Dave Kreskowiak 1,055