SQL "How-To" Question

Status
Not open for further replies.

Telematx

Ars Tribunus Militum
2,841
I've got a table in a database (MS SQL Server), with a text field (varchar(1)) that for each record is either "A" or "T".

I have another table, where the same data is a bit column (1 instead of A, 0 instead of T).

Is it possible to somehow, w/in a query, to cast/convert the varchar field to a bit, so I can do a join and compare the data? (And no, I can't permanently convert the column in the first table from varchar to bit :( )
 

indigo

Well-known member
5,606
It should be really easy inside of your program though.

There's probably lots of ways, but here's one off of the top o' me head in ASP/vbscript:

rs = Conn.Execute("SELECT strField FROM Table")
intCount = 0
arrField as array
While Not rs.EOF
Select Case rs("strField")
Case: "T"
arrField(intCount) = 0
Case: "A"
arrField(intCount) = 1
End Select
intCount = intCount + 1
rs.MoveNext
Wend

You can do it however you like though. You could use count(), or whatever... actually, I'm sure there has to be a really easy way to do what you want inside of a stored procedure, but I don't know how...
 
Status
Not open for further replies.