Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating View of TSQL statement result columns

Status
Not open for further replies.

tani1978

MIS
Sep 29, 2005
49
DE
Hello Friends,
I have this TSQL sytax which shows me a table of requested columns, I want to save these columns as a view. How can I implement this.Thanks in advance of your efforts.

Code:
SELECT (CONVERT(VARCHAR(12),[Dat],106)) AS Expression, 
SUM(CASE WHEN [Project] = 'ott' THEN [NO2] END) AS [ott]
FROM MyTable
WHERE (((Dat)>'2003/9/1') 
AND (([Project]) IN ('ott'))) 
GROUP BY (Year([Dat])*12+Month([Dat])-1), Dat, (CONVERT(VARCHAR(12),[Dat],106))
 
I am getting an error about the CASE keyword it is sorry for the wrong translation i am translating englisg from german.
The designer is not ready for CASE Construct.
 
Use Query Analyzer to create the view, EM doesn't like all CASE statements
just copy the code into QA and hit F5

Create View MyView
as
SELECT (CONVERT(VARCHAR(12),[Dat],106)) AS Expression,
SUM(CASE WHEN [Project] = 'ott' THEN [NO2] END) AS [ott]
FROM MyTable
WHERE (((Dat)>'2003/9/1')
AND (([Project]) IN ('ott')))
GROUP BY (Year([Dat])*12+Month([Dat])-1), Dat, (CONVERT(VARCHAR(12),[Dat],106))

“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" --
 
Thanks you are right in Query Analyzer it worked.:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top