|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Saturday, February 02, 2013 11:09 AM
Points: 97,
Visits: 180
|
|
Hi all, I have been trying to resolve this for hours but failed, hence have to post here. I have this vbscript:
Private Function CheckNeedSendMail() As Integer Dim startFilterDate As DateTime Dim endFilterDate As DateTime endFilterDate = CType(Dts.Variables("StgEndDate").Value, DateTime) startFilterDate = endFilterDate.AddHours(-25) Dim strStart As String = startFilterDate.ToString() Dim strEnd As String = endFilterDate.ToString()
Dim sqlConnStr As String = "Data Source=" & RdVarStr("DB_Server_Name") & ";Initial Catalog=" & RdVarStr("DB_Init_Cat") & ";Integrated Security=True;" Dim rowCounter As Integer Using sqlConn As New Data.SqlClient.SqlConnection(sqlConnStr) sqlConn.Open() Using sqlCmd As New Data.SqlClient.SqlCommand("SELECT Count(*) from RPT_TACS_ACCESS_DTL where EXIT_DT >= " & startFilterDate & " and EXIT_DT <= " & endFilterDate & " and WORKED_HRS >= (select VALUE from TERMACCESS_CONFIG where MODULE = 'SSIS TACSReport' and [KEY]= 'Var_WorkHrs_Limit') +':00'", sqlConn) Dim sqlDtReader As Data.SqlClient.SqlDataReader sqlDtReader = sqlCmd.ExecuteReader() While sqlDtReader.Read() rowCounter = sqlDtReader.GetInt32(0) End While sqlDtReader.Close() End Using End Using Return rowCounter
End Function I keep hitting incorrect syntax near '7' and '+' when i dont even have this two value.... what went wrong?????
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: 2 days ago @ 9:56 AM
Points: 4,418,
Visits: 7,156
|
|
Looks like it's to do with the way the command string is being built. Perphaps you could put a line in your code to print the command string before it's executed? What is the "+':00'" at the end for? If you're trying to append ":00" on to the end of a number, you need to do something like this:
SELECT CAST(COUNT(*) AS varchar(6)) + ':00' ... John
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Saturday, February 02, 2013 11:09 AM
Points: 97,
Visits: 180
|
|
John Mitchell-245523 (1/3/2013) Perphaps you could put a line in your code to print the command string before it's executed?
John
How do i do this?
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: 2 days ago @ 9:56 AM
Points: 4,418,
Visits: 7,156
|
|
That's more a VB question than a SQL Server question, and outside my area of expertise. You could try using MsgBox.
John
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Saturday, February 02, 2013 11:09 AM
Points: 97,
Visits: 180
|
|
John Mitchell-245523 (1/3/2013)
What is the "+':00'" at the end for? If you're trying to append ":00" on to the end of a number, you need to do something like this: SELECT CAST(COUNT(*) AS varchar(6)) + ':00' ... John
Thanks for helping. The "+':00'" is to add :00 to my variable to make the query works. For example after using sub query if the Var_WorkHrs_Limit is 07, then it will query WORKED_HRS >= 07:00 I have been using this way for another similar method and no problem for the script. I do not think that is the cause.
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Saturday, February 02, 2013 11:09 AM
Points: 97,
Visits: 180
|
|
John Mitchell-245523 (1/3/2013) That's more a VB question than a SQL Server question, and outside my area of expertise. You could try using MsgBox.
John
Oh i tried using msgbox to see whats wrong before posting here. MsgBox doesnt really helps pointing out where is the problem.
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: 2 days ago @ 9:56 AM
Points: 4,418,
Visits: 7,156
|
|
10e5x (1/3/2013) Oh i tried using msgbox to see whats wrong before posting here. MsgBox doesnt really helps pointing out where is the problem. Why not? If you put this in your code:
MsgBox("SELECT Count(*) from RPT_TACS_ACCESS_DTL where EXIT_DT >= " & startFilterDate & " and EXIT_DT <= " & endFilterDate & " and WORKED_HRS >= (select VALUE from TERMACCESS_CONFIG where MODULE = 'SSIS TACSReport' and [KEY]= 'Var_WorkHrs_Limit') +':00'") how does that not help? If it really doesn't, you'll need to do your own research to find out how to display the code some other way.
John
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: 2 days ago @ 10:13 AM
Points: 455,
Visits: 2,662
|
|
do you have to put quotes round your dates?
instead of
where EXIT_DT >= " & startFilterDate & " and you do
where EXIT_DT >= ' " & startFilterDate & " ' and
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 3:40 AM
Points: 496,
Visits: 583
|
|
Look at line 15, you are using two variables to represent your filter dates, but the string representation doesn't include the single quotes ' ' around the date. So you're putting together your SELECT clause without single quotes around the date variables. Try including the single quotes before and after each variable as part of the strings and see if that does the trick.
Your error message is simply due to SQL Server not being able to parse the line as 'single quotes' are required around values like these.
EDIT: Sorry davidandrews13, didn't spot your post above. Ditto that.
---
Note to developers: CAST(SUBSTRING(CAST(FLOOR(NULLIF(ISNULL(COALESCE(1,NULL),NULL),NULL)) AS CHAR(1)),1,1) AS INT) == 1 So why complicate your code AND MAKE MY JOB HARDER??!
Want to get the best help? Click here http://www.sqlservercentral.com/articles/Best+Practices/61537/ (Jeff Moden) My blog: http://uksqldba.blogspot.com Visit http://www.DerekColley.co.uk to find out more about me.
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: 2 days ago @ 8:46 AM
Points: 8,547,
Visits: 8,204
|
|
|
|
|