1

So i want to create 3 columns in my query. One of those columns in the query needs to be renamed and use values from the Composer column. This is what i have so far:

CREATE VIEW [Multiple Composers] AS
SELECT Name, Composer FROM Track 
WHERE Composer LIKE '%/%'
AND Composer NOT LIKE 'AC/DC'

Not sure how to go about doing this and would appreciative some advice

3
  • 1
    Use as NewName after the column. Commented May 18, 2016 at 1:51
  • As a follow up question. the third column was created but i'm not sure how i can apply a different where clause to the 3rd column. I wanted to have something like Where 3rd Column like '%, %' Commented May 18, 2016 at 2:44
  • third column is same as Composer you can put different clause on sam column or u have to create CTE or in line view ( sub query).. Commented May 18, 2016 at 3:00

1 Answer 1

1

You can create new columns from existing columns using AS Clause, which allows you to specify an alias name for items. If you want to create conditions upon newly created column, use a temporary table.

with tmpTable as
(select name, composer, composer as newComposer from Track)
select name, composer, newComposer from tmpTable where composer like'%/%' and newComposer not like 'AC/DC';
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I executed this and the Composer And newComposer columns are identical. if i where to make the clause newComposer like '%, %' so that one columns shows foward slashes and one shows commas how would i go about doing that?
In the where condition you can do anything with this newComposer column.Just change the condition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.