Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date select with string SQL-server ASP

Status
Not open for further replies.

marco021

Programmer
Sep 28, 2000
3
FR
I am trying to select date from my table on the sql-server. I am using a string for de datevalue.

The following code is working:
strDatum= "SELECT * FROM data WHERE (datum > convert(datetime,'12-10-2001'))"

The problem is that i have to use a string instead of '12-10-2001'.

dim Datum1
datum1 = request("datum")

the following selectstatement is not working;

strDatum = "SELECT * FROM data WHERE (datum > convert(datetime, datum1))"

What am i doing wrong?
Can annybody help me?
 
Try
<b><code>
strDatum= &quot;SELECT * FROM data WHERE datum>'12-10-2001'&quot;
or
strDatum= &quot;SELECT * FROM data WHERE datum>'&quot;&mydate&&quot;'&quot;
</code></b>
________
George, M
 
You would be better off writing the sql in a stored procedure to run on the server and just call the stored procedure in your asp page.

** stored procedure **
CREATE PROCEDURE [cspName]
@StartDate datetime

AS

Begin
Select *
From data
Where datum is Not Null And (datum > @StartDate
End
** End of Stored Procedure **

** Start of ASP call to Stored procedure **

dim datum1
datum1 = request(&quot;datum&quot;)
Set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Set objCmd = Server.CreateObject(&quot;ADODB.Command&quot;)
Set objRst = Server.CreateObject(&quot;ADODB.Recordset&quot;)

objConn.open &quot;PROVIDER=MSDASQL;&quot; & _
&quot;DRIVER={SQL Server};&quot; & _
&quot;SERVER=servername;DATABASE=dbname;&quot; & _
&quot;UID=userid;PWD=userpwd;&quot;
Dim RstNew
With objCmd
.ActiveConnection = objConn
.CommandText = &quot;cspName&quot;
.CommandType = adCmdStoredProc

'CREATE PARAMETERS, RETURN VALUE MUST BE FIRST PARAMETER!!
.Parameters.Append .CreateParameter(&quot;@StartDate&quot;, adDBTimeStamp, adParamInput, 8)
'SET PARAMETER VALUES
.Parameters(&quot;@StartDate&quot;)=strStartDate
Set RstNew = .Execute
End With

Just make sure the userID has execute permission on the stored procedure.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top