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 |
jp2code
Posting Yak Master
175 Posts |
Posted - 2009-01-26 : 14:27:39
|
Below is code that returns a nice table for me in Query Analyzer; however, if I try to run this in my Visual Studio 2005 project, I get this message:quote: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <-, >, >- or when the subquery is used as an expression.
Here is the code:CREATE PROCEDURE AcpReport_OpByMachine(@StartDate DateTime, @EndDate DateTime) AS/* Created by Joe Pool - searches all records for employee records on a machine This query is to fill a tree view control with Operator names */DECLARE @DATE1 DateTime, @DATE2 DateTime, @space char(1)SET @DATE1=@StartDateSET @DATE2=@EndDateSET @space=' 'SELECT DISTINCT T1.SYSTEM_ID as 'System_ID', (SELECT FIRSTNAME+@space+LASTNAME FROM EmployeeInfo WHERE NUM=T1.OP_ID) AS 'Operator' FROM ACP_PARTS T1WHERE (T1.[DATE_TIME] BETWEEN @DATE1 AND @DATE2) UNIONSELECT DISTINCT 'Acp_Packout_'+SubString(Cast(DatePart(Year, T2.[Date_Time]) as VarChar(4)), 3, 2) as 'System_ID', (SELECT FIRSTNAME+@space+LASTNAME FROM EmployeeInfo WHERE NUM=T2.OP_ID) AS 'Operator' FROM BOX_DATA T2WHERE (T2.[DATE_TIME] BETWEEN @DATE1 AND @DATE2) UNIONSELECT DISTINCT T3.SYSTEM_ID as 'System_ID', (SELECT FIRSTNAME+@space+LASTNAME FROM EmployeeInfo WHERE NUM=T3.OP_ID) AS 'Operator' FROM Final_Check T3WHERE (T3.[DATE_TIME] BETWEEN @DATE1 AND @DATE2) UNIONSELECT DISTINCT CASE WHEN 0 < (CharIndex(@space, T4.SYSTEM_ID)) THEN SubString(T4.SYSTEM_ID, 1, CharIndex(@space, T4.SYSTEM_ID)) ELSE T4.SYSTEM_ID END as 'System_ID', T4.OP_ID AS 'Operator' FROM TEST_RESULTS T4WHERE (T4.[DATE_TIME] BETWEEN @DATE1 AND @DATE2)GO Avoid Sears Home Improvement |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
jp2code
Posting Yak Master
175 Posts |
Posted - 2009-01-26 : 15:02:25
|
Thanks tkizer. Now, Visual Studio doesn't complain.Now I have another problem: Only the last table is returning any data.Do you see something incorrect in this newest version?DECLARE @DATE1 DateTime, @DATE2 DateTime, @space char(1)SET @DATE1=@StartDateSET @DATE2=@EndDateSET @space=' 'SELECT T1.SYSTEM_ID as 'System_ID', NUM AS 'Operator'FROM ACP_PARTS T1 INNER JOIN EmployeeInfo ON NUM=T1.[OP_ID]WHERE (T1.[DATE_TIME] BETWEEN @DATE1 AND @DATE2) UNIONSELECT 'Acp_Packout_'+SubString(Cast(DatePart(Year, T2.[Date_Time]) as VarChar(4)), 3, 2) as 'System_ID', NUM AS 'Operator'FROM BOX_DATA T2 INNER JOIN EmployeeInfo ON NUM=T2.[OP_ID]WHERE (T2.[DATE_TIME] BETWEEN @DATE1 AND @DATE2) UNIONSELECT T3.SYSTEM_ID as 'System_ID', NUM AS 'Operator'FROM Final_Check T3 INNER JOIN EmployeeInfo ON NUM=T3.[OP_ID]WHERE (T3.[DATE_TIME] BETWEEN @DATE1 AND @DATE2) UNIONSELECT CASE WHEN 0 < (CharIndex(@space, T4.SYSTEM_ID)) THEN SubString(T4.SYSTEM_ID, 1, CharIndex(@space, T4.SYSTEM_ID)) ELSE T4.SYSTEM_ID END as 'System_ID', T4.OP_ID AS 'Operator'FROM TEST_RESULTS T4WHERE (T4.[DATE_TIME] BETWEEN @DATE1 AND @DATE2)GO Avoid Sears Home Improvement |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
jp2code
Posting Yak Master
175 Posts |
Posted - 2009-01-26 : 15:34:17
|
Oh! Yes, I just found it and was coming here to update.Thanks for your excellent help. Avoid Sears Home Improvement |
|
|
|
|
|
|
|