RIAS
asked on
Stored procedure to find existing record
Hello,
I have a stored procedure to find existing record in the table.if it exists I am updating thetable and if not I am inserting the row.
It works fine for varchar/nvarchar but fais for money datatype.
Table1 has colmoney1 which is null and I try to insert another row which has value null it still tries to insert the record though similar null erecord already exist in table
total is the money column
Any conversion need to be done for total to check null ?
I have a stored procedure to find existing record in the table.if it exists I am updating thetable and if not I am inserting the row.
It works fine for varchar/nvarchar but fais for money datatype.
Table1 has colmoney1 which is null and I try to insert another row which has value null it still tries to insert the record though similar null erecord already exist in table
total is the money column
Any conversion need to be done for total to check null ?
ASKER
Total is a money datatype column
try:
AND coalesce([Total],"") = @Total
(assuming your parameter is not null but an empty string)
AND coalesce([Total],"") = @Total
(assuming your parameter is not null but an empty string)
ASKER
Arana,Cheers! will try and get back mate
ASKER
Still the same,the parameter looks like null .
I get correct correct results when I query total is null and no results if I query total =''
I get correct correct results when I query total is null and no results if I query total =''
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Any conversion need to be done for total to check null ?Yes!
Where is @Total declared and what type is it? Are you meaning the @Total value to check is NULL or the column value you are checking against in the database is NULL or both?
You say "Table1 has colmoney1" but I do not see that column anywhere in your query so I do not know what needs to be looked at to correct. You reference total or @total several places.
ASKER
"Table1 has colmoney1" was just an example.
Total is the money column .
Need to check against in the database is NULL
Total is the money column .
Need to check against in the database is NULL
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sure
ASKER
Chris Special thanks for the concern
ASKER
Arana,
This worked :
([Total] = @Total OR
([Total] is null AND @Total is null) OR
([Total] is null AND @Total ='') OR
([Total] ='' AND @Total is null)
This worked :
([Total] = @Total OR
([Total] is null AND @Total is null) OR
([Total] is null AND @Total ='') OR
([Total] ='' AND @Total is null)
I was going to suggest the same thing as Arana, that's why I marked it as a good comment. Glad you got it working!
*edit
*edit
ASKER
Open in new window