-1

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 the table: enter image description here

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

enter image description here

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

enter image description here

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

enter image description here

Does anyone have any thoughts? I really appreciate your help.

Drake .C
  • 332
  • 4
  • 16
  • Please read http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question/285557 and the accepted answer –  Jun 06 '18 at 20:34
  • 1
    Its posting the results to text instead of results to grid. Are you sure you didn't click this at the top of SSMS? [**Here's a picture**](https://stackoverflow.com/a/20012621/6167855) – S3S Jun 06 '18 at 20:39
  • 2
    @scsimon Thank you so much, it works. I am not sure how it would be selected. I've restart and open a new query to do it. But it still stays in 'to txt' model . – Drake .C Jun 06 '18 at 20:46
  • haha! I do that all the time. – Alan Burstein Jun 06 '18 at 20:47

1 Answers1

0

Thanks to @scsimon who answered my question in the commands. I accidentally hit the 'results to text' button. Can't believe I spent an hour on such a stupid question.

Drake .C
  • 332
  • 4
  • 16