COALESCE and bit values.

  • hi there

    I have a stored procedure that inserts values from a web form into 3 tables. The stored procedure inserts the compulsory values into the first table, and then should take the id value to insert into the 2nd and 3rd tables.

    As I only want to insert values into the 2nd and 3rd tables if they were populated, I am using COALESCE to check if there were values submitted to the stored procedure. There are 4 char values and a bit value. COALESCE won't work with the bit in the list. It returns the error 'Syntax error converting the varchar value '12:00' to a column of data type bit.' I thought that all COALESCE did was return the first non-null value... It works fine when the bit value is excluded from the list.

    Can you not use bit values in COALESCE, or have I made an obvious mistake...?!

  • From BOL:

    quote:


    All expressions must be of the same type or must be implicitly convertible to the same type.


    Try changing the order in the COALESCE. Maybe it takes the type of the last parameter as the effective type to convert to?

  • oops- my fault for not reading BOL properly.

    thanks!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply