Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Karander
Starting Member
34 Posts |
Posted - 2004-09-06 : 10:58:24
|
| Hi! I would like to pass to varchars' variable data and boolean. How to convert string data (and in what format) to "date" and true or false to boolean?Really thanks |
|
|
mwjdavidson
Aged Yak Warrior
735 Posts |
Posted - 2004-09-06 : 11:12:38
|
| You can convert a string to a date using the CONVERT function:SELECT CONVERT(datetime, '1/jan/2004')If your string is ambiguous (i.e. '10/12/04'), you will need to tell sql server how to interpret it as follows:SET DATEFORMAT dmy --Producing 10/Dec/2004SET DATEFORMAT mdy --Producing 12/Oct/2004etc.You can convert a boolean as follows:SELECT CASE MyTextField WHEN 'True' THEN 1 WHEN 'False' THEN 0 END AS MyBooleanFieldFROM MyTableMark |
 |
|
|
Karander
Starting Member
34 Posts |
Posted - 2004-09-06 : 11:49:35
|
Hi! Really thanks. With data i solved problem, but with boolean not.I have to pass as a varchar parameter boolean (it can be 0 or 1) and compare with boolean field inside procedure.In my program it doesn;t work: (However it can be funny if you see it) :)if tablica.bool then str := str + ' case "true" when "true" then 1 end as boolfield ' else str := str + ' case "false" when "false" then 0 end as boolfield ';?quote: [i]Originally posted by mwjdavidson You can convert a string to a date using the CONVERT function:SELECT CONVERT(datetime, '1/jan/2004')If your string is ambiguous (i.e. '10/12/04'), you will need to tell sql server how to interpret it as follows:SET DATEFORMAT dmy --Producing 10/Dec/2004SET DATEFORMAT mdy --Producing 12/Oct/2004etc.You can convert a boolean as follows:SELECT CASE MyTextField WHEN 'True' THEN 1 WHEN 'False' THEN 0 END AS MyBooleanFieldFROM MyTableMark |
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2004-09-06 : 18:05:06
|
| boolfield = case @boolparam when '1' then 1 else 0 endrockmoose/* Chaos is the nature of things...Order is a lesser state of chaos */ |
 |
|
|
|
|
|