This question is a little bit silly but I am really kind of stuck here. I was doing a simple select query, trying to the union it with other queries and finally save them as a view. However, as long as I use 'create view', the query results will turn into lines with commas instead of rows. I do know how to turn query tables into comma results but I don't know how to make a query results stay in the table format.
Here is my query to get the results and combine the results:
SELECT DISTINCT SUBSTRING(serialnumber, 34, 9), 'PCBA-10215-0001', testrunstarttime
FROM [dbo].[boardtestresults1_full_view]
WHERE partnumber = 'PCBA-10215-0001' AND overalltestrunstatus = 'pass'
GROUP BY serialnumber, testrunstarttime
HAVING Count(DISTINCT combined) >= 97
UNION
-- 1946 / 2189
SELECT DISTINCT SUBSTRING(serialnumber, 34, 9), 'PCBA-10214-0001', testrunstarttime
FROM [dbo].[boardtestresults1_full_view]
WHERE partnumber = 'PCBA-10214-0001' AND overalltestrunstatus = 'pass'
GROUP BY serialnumber, testrunstarttime
HAVING Count(DISTINCT combined) >= 107
Here is my query to create the view, and it screwed up everything.
CREATE VIEW TEST5 AS
-- 2042/2052
SELECT DISTINCT SUBSTRING(serialnumber, 34, 9) AS col_1, 'PCBA-10215-0001'AS col_2, testrunstarttime
FROM [dbo].[boardtestresults1_full_view]
WHERE partnumber = 'PCBA-10215-0001' AND overalltestrunstatus = 'pass'
GROUP BY serialnumber, testrunstarttime
HAVING Count(DISTINCT combined) >= 97
UNION
-- 1946 / 2189
SELECT DISTINCT SUBSTRING(serialnumber, 34, 9)AS col_1, 'PCBA-10214-0001'AS col_2, testrunstarttime
FROM [dbo].[boardtestresults1_full_view]
WHERE partnumber = 'PCBA-10214-0001' AND overalltestrunstatus = 'pass'
GROUP BY serialnumber, testrunstarttime
HAVING Count(DISTINCT combined) >= 107
Even if I remove the code and type a new line after executing this I will get such kind of results.
SELECT DISTINCT SUBSTRING(serialnumber, 34, 9)AS col_1, 'PCBA-10214-0001'AS col_2, testrunstarttime
FROM [dbo].[boardtestresults1_full_view]
WHERE partnumber = 'PCBA-10214-0001' AND overalltestrunstatus = 'pass'
GROUP BY serialnumber, testrunstarttime
HAVING Count(DISTINCT combined) >= 107
Does anyone have any thoughts? I really appreciate your help.