LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DB Tools Execute Query does not work correctly

If I connect to an sql server manually using DB Tools Open Connec.VI the SQL query below (QUERY 1)  works fine, but when I connect to the data base automatically using a connection string QUERY 1 does not work unless I modify as shown in QUERY 2 with all variables removed. Is there a limit on the number of characters allowed when using DB Tools Execute Query.VI?  Does DB Tools Execute Query.VI not allow the use of variables in the query? 
 
--QUERY 1
------------------------------------------------
declare @TestName as varchar(800)
declare @StartTime as datetime
declare @EndTime as datetime
set @TestName = 'SFR_LowerLeft'
set @StartTime = '2007-07-09 16:28:57'
set @EndTime = '2007-07-13 16:29:04'
select
 t.name 'Test',
 st.description 'Station',
 mdp.name 'Test Step',
 mdp.value 'Value',
 mdp.hilim 'High Limit',
 mdp.lolim 'Low Limit'
from
 dbo.ffMeasurementDetailPass mdp
 inner join
 fftest t on t.id = mdp.testid
 inner join
 ffserialnumber s on s.unitid = t.unitid
 inner join
 ffstation st on st.id = t.stationid
where
 mdp.name =  @TestName and
        testerstarttime >= @StartTime and
 testerstarttime <= @EndTime and
        st.description in ('L1-FOCTEST-01')
 
 
--QUERY 2
----------------------------------------------------------
select
 t.name 'Test',
 st.description 'Station',
 mdp.name 'Test Step',
 mdp.value 'Value',
 mdp.hilim 'High Limit',
 mdp.lolim 'Low Limit'
from
 dbo.ffMeasurementDetailPass mdp
 inner join
 fftest t on t.id = mdp.testid
 inner join
 ffserialnumber s on s.unitid = t.unitid
 inner join
 ffstation st on st.id = t.stationid
where
 mdp.name =  'SFR_LowerLeft' and
        testerstarttime >= '2007-07-09 16:28:57' and
 testerstarttime <= '2007-07-13 16:29:04' and
        st.description in ('L1-FOCTEST-01')
 
 
 
0 Kudos
Message 1 of 3
(2,382 Views)
You'll have to use the "DB Tools Create Parameterized Query" to pass your variables. The other option is to not use the DB Connectivity Toolkit at all as some here have suggested (you'll find other solutions if you search the forum) due to varying levels of dissatisfaction with the Toolkit.
0 Kudos
Message 2 of 3
(2,378 Views)
You might want to check out this thread.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 3 of 3
(2,358 Views)