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 |
|
fuzzyip
Starting Member
35 Posts |
Posted - 2008-07-17 : 12:21:32
|
| I have an easy stored procedureALTER procedure [dbo].[anlookup] @datebegin char(20), @dateend char(20), @state varchar(30)as beginselect *from ANInventorymmwhere max between '@datebegin 0:00:01 am' and '@dateend 23:59:59 pm' and city like '%@state%'endThe max column in table ANInventorymm is in a datetime format where all the dates look like this, '7/17/2008 2:42:31 AM'When I run the stored proc with something like this...anlookup '7/17/2008', '7/17/2008', 'california'i get, Msg 241, Level 16, State 1, Procedure anlookup, Line 7Conversion failed when converting datetime from character string.Anyone have any insight on this? |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-07-17 : 12:34:17
|
I assume your date column is of a DATETIME datatype ? Is your datacolumn named: [max] ?try this:ALTER procedure [dbo].[anlookup] @datebegin datetime,@dateend datetime,@state varchar(30)as beginselect <columnList>from ANInventorymmwhere <YourDateColumn> >= @datebeginand <YourDateColumn> < dateadd(day, +1, @dateend)goexec anlookup '2008-07-17', '2008-07-17', 'california' Be One with the OptimizerTG |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-07-17 : 12:35:35
|
quote: Originally posted by fuzzyip I have an easy stored procedureALTER procedure [dbo].[anlookup] @datebegin char(20), @dateend char(20), @state varchar(30)as beginselect *from ANInventorymmwhere max between '@datebegin 0:00:01 am' and '@dateend 23:59:59 pm' and city like '%@state%'endThe max column in table ANInventorymm is in a datetime format where all the dates look like this, '7/17/2008 2:42:31 AM'When I run the stored proc with something like this...anlookup '7/17/2008', '7/17/2008', 'california'i get, Msg 241, Level 16, State 1, Procedure anlookup, Line 7Conversion failed when converting datetime from character string.Anyone have any insight on this?
Put this datetime or smalldatetime instead. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-17 : 12:39:29
|
quote: Originally posted by fuzzyip I have an easy stored procedureALTER procedure [dbo].[anlookup] @datebegin char(20), @dateend char(20), @state varchar(30)as beginselect *from ANInventorymmwhere max between '@datebegin 0:00:01 am' and '@dateend 23:59:59 pm' and city like '%@state%'endThe max column in table ANInventorymm is in a datetime format where all the dates look like this, '7/17/2008 2:42:31 AM'When I run the stored proc with something like this...anlookup '7/17/2008', '7/17/2008', 'california'i get, Msg 241, Level 16, State 1, Procedure anlookup, Line 7Conversion failed when converting datetime from character string.Anyone have any insight on this?
no need to append time like that, just useselect *from ANInventorymmwhere max >@datebegin and max <dateadd(d,1,@dateend) and city like '%'+@state+'%' |
 |
|
|
fuzzyip
Starting Member
35 Posts |
Posted - 2008-07-17 : 12:54:39
|
quote: Originally posted by visakh16
quote: Originally posted by fuzzyip I have an easy stored procedureALTER procedure [dbo].[anlookup] @datebegin char(20), @dateend char(20), @state varchar(30)as beginselect *from ANInventorymmwhere max between '@datebegin 0:00:01 am' and '@dateend 23:59:59 pm' and city like '%@state%'endThe max column in table ANInventorymm is in a datetime format where all the dates look like this, '7/17/2008 2:42:31 AM'When I run the stored proc with something like this...anlookup '7/17/2008', '7/17/2008', 'california'i get, Msg 241, Level 16, State 1, Procedure anlookup, Line 7Conversion failed when converting datetime from character string.Anyone have any insight on this?
no need to append time like that, just useselect *from ANInventorymmwhere max >@datebegin and max <dateadd(d,1,@dateend) and city like '%'+@state+'%'
when I change it to that, the storedproc won't update sucessfully, Msg 102, Level 15, State 1, Procedure anlookup, Line 15Incorrect syntax near '%'. |
 |
|
|
fuzzyip
Starting Member
35 Posts |
Posted - 2008-07-17 : 12:56:46
|
quote: Originally posted by TG I assume your date column is of a DATETIME datatype ? Is your datacolumn named: [max] ?try this:ALTER procedure [dbo].[anlookup] @datebegin datetime,@dateend datetime,@state varchar(30)as beginselect <columnList>from ANInventorymmwhere <YourDateColumn> >= @datebeginand <YourDateColumn> < dateadd(day, +1, @dateend)goexec anlookup '2008-07-17', '2008-07-17', 'california' Be One with the OptimizerTG
I tried this also and getMsg 102, Level 15, State 1, Procedure anlookup, Line 13Incorrect syntax near ')'. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-17 : 12:56:49
|
quote: Originally posted by fuzzyip
quote: Originally posted by visakh16
quote: Originally posted by fuzzyip I have an easy stored procedureALTER procedure [dbo].[anlookup] @datebegin char(20), @dateend char(20), @state varchar(30)as beginselect *from ANInventorymmwhere max between '@datebegin 0:00:01 am' and '@dateend 23:59:59 pm' and city like '%@state%'endThe max column in table ANInventorymm is in a datetime format where all the dates look like this, '7/17/2008 2:42:31 AM'When I run the stored proc with something like this...anlookup '7/17/2008', '7/17/2008', 'california'i get, Msg 241, Level 16, State 1, Procedure anlookup, Line 7Conversion failed when converting datetime from character string.Anyone have any insight on this?
no need to append time like that, just useselect *from ANInventorymmwhere max >@datebegin and max <dateadd(d,1,@dateend) and city like '%'+@state+'%'
when I change it to that, the storedproc won't update sucessfully, Msg 102, Level 15, State 1, Procedure anlookup, Line 15Incorrect syntax near '%'.
are you using sql server? if yes, post full query used. |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-17 : 12:56:54
|
| show us what you actually have.you're sure you didn't just miss off the 'END' or something?Em |
 |
|
|
fuzzyip
Starting Member
35 Posts |
Posted - 2008-07-17 : 12:59:24
|
quote: Originally posted by elancaster show us what you actually have.you're sure you didn't just miss off the 'END' or something?Em
christ, that was it, I missed the ENDlol Thanks guys, much appreciated |
 |
|
|
|
|
|
|
|