June 24, 2008 at 7:12 am
hi friends,
i m just writing simple query which insert record into table. But before selecting record it should have some condition to match and it gives error.
declare @startdate datetime
declare @enddate datetime
declare @ward varchar(20)
set @startdate = '20071201'
set @enddate = '20071231'
set @ward = 'AAA'
insert into NPI (total, monthname, type, ward)
if (select count(ward) from NPI_Table where monthname = getdate() and ward = @ward and type = 'CDiff') = '0'
begin
select '0' as total,
getdate() as date,
'CD' as type, @ward as ward
end
else
begin
select isnull(total, 0) as total, monthname, type, ward from NPI_Table
where monthname = getdate()
and ward = @ward
and type = 'CD'
end
Here if i take out insert statement, it works fine. But it gives problem with insert. The table is having same 4 fields which is selected.
Any Suggestion?
June 24, 2008 at 7:17 am
/*
Dear Friend,
Try below mentioned code....
----------------------------------
*/
declare @startdate datetime
declare @enddate datetime
declare @ward varchar(20)
set @startdate = '20071201'
set @enddate = '20071231'
set @ward = 'AAA'
if (select count(ward) from NPI_Table where monthname = getdate() and ward = @ward and type = 'CDiff') = '0'
begin
insert into NPI (total, monthname, type, ward)
select '0' as total,
getdate() as date,
'CD' as type, @ward as ward
end
else
begin
insert into NPI (total, monthname, type, ward)
select isnull(total, 0) as total, monthname, type, ward from NPI_Table
where monthname = getdate()
and ward = @ward
and type = 'CD'
end
June 24, 2008 at 7:18 am
Yep... suggestion is that you post the code that has the problem insert so we can see what you're actually doing and post the text from the actual error so we can see that, as well.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 24, 2008 at 7:20 am
Hi Hari,
Bluddy hell.....why i didnt think about it...it was so easy....thanks very much....
thankssss
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply