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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-06-13 : 08:52:03
|
| Mike writes "Here is a boiled down example of a more complex scenario:=====================================declare @dateType varchar(16)set @dateType = 'wk'select datepart (@dateType, getdate())=====================================but it results in: =====================================Server: Msg 1023, Level 15, State 3, Line 4Invalid parameter 1 specified for datepart.=====================================Of course running the same select statement using what SQL Server is expecting -wk- as the first parameter works fine. So how can I cast/convert my string into this enumeration or in general any enumerations in SQL Server?I'm running SQL 2000/2005 on Windows 2003." |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-06-13 : 09:05:36
|
| 1 Use Dynamic SQLdeclare @dateType varchar(16)set @dateType = 'wk'exec('select datepart ('+@dateType+', getdate())')2 Use if conditiondeclare @dateType varchar(16)set @dateType = 'wk'if @dateType='wk' select datepart (wk, getdate())Second method is advisible to useMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|