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 |
|
lfmn
Posting Yak Master
141 Posts |
Posted - 2003-08-07 : 12:58:29
|
| Is there any way to determine the data type of a variable in SQL Server 2000?For example:declare @datatype varchar(30)set @datatype = 'string'Is there a command which then will output the data type of @datatype?SQL is useful if you don't know cursors :-) |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-08-07 : 13:12:08
|
Do you mean something like:DECALRE @localVar varchar(30)set @localVar = 'string'SELECT CASE WHEN ISDATE(@localVar)=1 THEN 'datetime' WHEN ISNUMERIC(@localVar)=1 THEN 'date' ELSE 'char' END Brett8-)SELECT POST=NewId() |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-08-07 : 13:13:32
|
| Why would you want to do what the data type is when you just declared it? What are you trying to do?Tara |
 |
|
|
lfmn
Posting Yak Master
141 Posts |
Posted - 2003-08-07 : 13:26:27
|
| I was just using a simple example to illustrate my point. In my simple example OF COURSE I know what the data type is. I'm having a problem with data types and I'm trying to see if there is a way in Query Analyzer to output the data type.SQL is useful if you don't know cursors :-) |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-08-07 : 13:30:01
|
| Have you looked at the INFORMATION_SCHEMA views yet?SELECT DATA_TYPEFROM INFORMATION_SCHEMA.COLUMNSWHERE COLUMN_NAME = 'SomeColumn' AND TABLE_NAME = 'SomeTable'Tara |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-08-07 : 13:30:03
|
| Can't think of any reason to get the datatype of a variable.isdate and isnumeric and patindex will tell you about the data a variable contains.syscolumns or information_schema.columns will tell you the datatype of fields.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
lfmn
Posting Yak Master
141 Posts |
Posted - 2003-09-02 : 07:45:13
|
quote: Originally posted by nr Can't think of any reason to get the datatype of a variable.isdate and isnumeric and patindex will tell you about the data a variable contains.syscolumns or information_schema.columns will tell you the datatype of fields.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy.
I've been doing too much C# programming and forgetting my SQL. I wanted to check the data type because when it was passed in our code did not return the correct results, but when a data was hard-coded into the code, it did return the correct results. This made me question whether it was being passed in correctly as a date. Using the isdate() function, I determined that SQL Server was recognizing it as a date, but still not executing the code correctly. The problem was fixed by installing Service Pack 3.SQL is useful if you don't know cursors :-) |
 |
|
|
|
|
|