-
Oct 21st, 2004, 12:58 PM
#1
SQL Update on Bit field (Resolved)
I'm having a strange problem with an update query. I have an update line that includes a set statement like this:
SET Injected = " & injected & "
The column Injected is a bit field, and the variable injected is a boolean. In this query, I get an error saying the column name is invalid. I assume that I have to enclose the variable in some kind of punctuation, but I can't figure out what.
I was able to work around it by interpreting the boolean as an integer (1/0) which works fine when put into the statement.
I assume this is simple, but I haven't done it before, and haven't seen any usefull reference for it.
Last edited by Shaggy Hiker; Oct 21st, 2004 at 01:59 PM.
My usual boring signature: Nothing
-
Oct 21st, 2004, 01:20 PM
#2
There is no puntuation required for a Bit field, treat it as a numeric.
A bit field can only be 0 or 1, in VB a boolean variable concatenated to a string will be the word True. So your SQL statement ends up being
Set Injected = True
SQL Server does not support the above statement and thinks the word True is another field. I think MS Access supports this statement but don't know for sure
Anyways, use the following to generate the SQL Statement.
Set Injected = " & ABS(Injected)
-
Oct 21st, 2004, 01:26 PM
#3
A bit field can only be 0 or 1
Ooops - Bit fields can also be Null of course.
-
Oct 21st, 2004, 01:58 PM
#4
Bit fields cannot be NULL in T-SQL.
Your answer surprises me. I expected that SQL would interpret the variable, as it does in an INSERT statement, but obviously not.
Thanks.
My usual boring signature: Nothing
-
Oct 21st, 2004, 02:47 PM
#5
Bit fields cannot be NULL in T-SQL.
Sure they can. Since version 7.0 I believe but maybe it was 2K.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|