SQLTeam.com | Weblogs | Forums

In Query - Autofill new column

sql2008r2
sql2012
sql2008

#1

** :chug: :toast:

Hello Everyone. This might be very simple, but need some help. I get records from a query whose status is "Marked". I need another column to be added to result set which just says "Marked" for every record. Is that possible in query?**


#2

You can add a column to the end of the SELECT list in your existing query. Alternatively you can keep the existing query unchanged and wrap it in an outer query like shown below:

SELECT
	*,
	'Marked' AS StatusColumn
FROM
(
	YourExistingQueryHere
) s

If you have an ORDER BY clause in your existing query, you will have to remove that and add that back at the very end. So on second thoughts, it is best to modify your existing query to include the Status column


#3

ERROR #50805215
Query failed to execute. GDS Exception. 335544569. Dynamic SQL Error
SQL error code = -104
Token unknown - line 1, column 9
, (comma)

My query is so simple.

SELECT
so.num AS ordernum, so.customercontact, so.dateissued, so.datecreated, so.datecompleted

FROM ship
LEFT JOIN so ON so.id = ship.soid
WHERE ship.statusid = 20


#4

"Marked" as status worked. Thanks so much.