[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

What is the syntax for saving a boolean value into SQLEXPRESS 2008?

I have a column in several tables called InUse.  The value is set to True if a user is editing that record.  I have tried many ways to save it, but none of them have worked.  This is the code I have now.  The zero at the end is for my InUse field, which in this case I'm trying to get it to save as False, which is what the value of obj4.InUse is.  Can you help?  This doesn't work.

mySQL = "INSERT INTO Users " & _
                            "(UserID,LoginName,Password,Last,First,Email,Phone) " & _
                            "VALUES (" & _
                            "'" & obj4.UserID & "'," & _
                            "'" & obj4.LoginName & "'," & _
                            "'" & obj4.Password & "'," & _
                            "'" & obj4.Last & "'," & _
                            "'" & obj4.First & "'," & _
                            "'" & obj4.Email & "'," & _
                            "'" & obj4.Phone & "'," & _
                            " 0);"
0
Agent909
Asked:
Agent909
  • 2
  • 2
1 Solution
 
HainKurtSr. System AnalystCommented:
try

mySQL = "INSERT INTO Users " & _
                            "(UserID,LoginName,Password,Last,First,Email,Phone,InUse) " & _
                            "VALUES (" & _
                            "'" & obj4.UserID & "'," & _
                            "'" & obj4.LoginName & "'," & _
                            "'" & obj4.Password & "'," & _
                            "'" & obj4.Last & "'," & _
                            "'" & obj4.First & "'," & _
                            "'" & obj4.Email & "'," & _
                            "'" & obj4.Phone & "'," & _
                            " 0);"
0
 
HainKurtSr. System AnalystCommented:
problem is iInUse is not in your column list...
0
 
Agent909Author Commented:
I just got this to work.  I forgot to add "UserID" after Phone on the second like.  Duh!  thanks anyway!
0
 
Agent909Author Commented:
We must've figured it out at about the same time.  I will award you the points.  I may have another question in a while.  Thanks again!
0
 
leakim971PluritechnicianCommented:
Hello Agent909,

You should use the "bit" datatype : http://msdn.microsoft.com/en-us/library/aa258271(SQL.80).aspx
And CAST : http://msdn.microsoft.com/en-us/library/ms187928.aspx

CAST('true' AS BIT) return 1
CAST('false' AS BIT) return 1

Regards.
mySQL = "INSERT INTO Users " & _
                            "(UserID,LoginName,Password,Last,First,Email,Phone) " & _
                            "VALUES (" & _
                            "'" & CAST(obj4.UserID AS BIT) & "'," & _
                            "'" & CAST(obj4.LoginName AS BIT) & "'," & _
                            "'" & CAST(obj4.Password AS BIT) & "'," & _
                            "'" & CAST(obj4.Last AS BIT) & "'," & _
                            "'" & CAST(obj4.First AS BIT) & "'," & _
                            "'" & CAST(obj4.Email AS BIT) & "'," & _
                            "'" & CAST(obj4.Phone AS BIT) & "'," & _
                            " 0);"

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now