If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Dynamic Dates and Stored Procedures

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-02-03, 11:53
brentb brentb is offline
Registered User
 
Join Date: Dec 2002
Location: Denver
Posts: 2
Dynamic Dates and Stored Procedures

I was wondering if anyone could help me past a problem that I am having using dynamic dates and stored procedures. I am new to this and have the following procedure written, This particular query will only return data if the variables @sDateFrom and @sDateTo are surrounded by single quotes however, in the stored procedure the single quotes cause the query to fail giving the error "Syntax error converting datetime from character string"

Any insights would be greatly appreciated.

Thanks,
Brent

ALTER PROC prBuildSelector (
@sNRW varchar(50),
@sDateFrom datetime,
@sDateTo datetime
)
AS

SELECT name,start_date,end_date, sku FROM product
INNER JOIN section ON product.pfid = section.pfid
WHERE product.name LIKE '%@sNRW%' AND
start_date > @sDateFrom
AND start_date < @sDateTo
ORDER BY vcfeb10_product.name
Return
Reply With Quote
  #2 (permalink)  
Old 01-06-03, 20:59
rnealejr rnealejr is offline
Registered User
 
Join Date: Feb 2002
Posts: 2,232
Which database are you using ?
Reply With Quote
  #3 (permalink)  
Old 01-09-03, 04:25
zORGLuB zORGLuB is offline
Registered User
 
Join Date: Jan 2003
Posts: 1
Re: Dynamic Dates and Stored Procedures

Quote:
Originally posted by brentb
I was wondering if anyone could help me past a problem that I am having using dynamic dates and stored procedures. I am new to this and have the following procedure written, This particular query will only return data if the variables @sDateFrom and @sDateTo are surrounded by single quotes however, in the stored procedure the single quotes cause the query to fail giving the error "Syntax error converting datetime from character string"

Any insights would be greatly appreciated.

Thanks,
Brent

ALTER PROC prBuildSelector (
@sNRW varchar(50),
@sDateFrom datetime,
@sDateTo datetime
)
AS

SELECT name,start_date,end_date, sku FROM product
INNER JOIN section ON product.pfid = section.pfid
WHERE product.name LIKE '%@sNRW%' AND
start_date > @sDateFrom
AND start_date < @sDateTo
ORDER BY vcfeb10_product.name
Return

EXEC('SELECT name,start_date,end_date, sku FROM product
INNER JOIN section ON product.pfid = section.pfid
WHERE product.name LIKE ''%' + @sNRW + '%'' AND
start_date > @sDateFrom
AND start_date < @sDateTo
ORDER BY vcfeb10_product.name')
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On