insert data

Last Post 20 Oct 2009 11:46 AM by JASBRYDEN. 4 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
JASBRYDEN
New Member
New Member

--
20 Oct 2009 05:43 AM
Hi

I would like to add a line of data into the table belteksales when chargeamount is not equal to 0

this is the code I have, but I do not think it is the correct format.

if chargeamount <>'0'
begin
insert into belteksales (WarehouseNo, Salesrepname, Invoiceno, Customerno, BillTo, BillName, CashAmount, Tax1total, InvoiceTotal)
values ('NA','NA','NA','NA','NA','NA','0.00','0.00','0.00')
end


what do you think I can do ??
dale123
New Member
New Member

--
20 Oct 2009 08:47 AM
The TSQL for the insert and the structure looks ok.

Where does the value of ChargeAmount come from?
Is it from this table or another table?

you would have to change the if statement to something like;

if (select ChargeAmount from table where column = value) = 0
begin
INSERT
end

JASBRYDEN
New Member
New Member

--
20 Oct 2009 11:46 AM
Then my SQL statement should look like this


if (select ChargeAmount from belteksales where chargeamount='0')
begin
insert into belteksales (WarehouseNo, Salesrepname, Invoiceno, Customerno, BillTo, BillName, CashAmount, Tax1total, InvoiceTotal)
values ('NA','NA','NA','NA','NA','NA','0.00','0.00','0.00')
end



I not sure that would work I would get an error

let me check
dale123
New Member
New Member

--
21 Oct 2009 03:11 AM
The problem looks like the if statement - it has to compare something and evaluate to a Boolean.

it could be
if (select ChargeAmount from belteksales where chargeamount='0') = 0
begin
end

If there are no rows matching the select statement then it should return null, which doesn't equal 0 so the if would be false.
If there are rows matching the select stetement then i would return 0 making the if return true.
JASBRYDEN
New Member
New Member

--
21 Oct 2009 06:43 AM
OK OK OK

I got you.

Thanks is works perfect now



Acceptable Use Policy
---