Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Issue with View in SQL2012
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ryankeast
Starting Member

9 Posts

Posted - 11/08/2013 :  03:31:37  Show Profile  Reply with Quote
Hi there,

I am having an issue with a script and I have got to the bottom of the troublesome part, but am unsure how to fix it.

When I run the below code in New Query window in Management Studio it works as I expect. When I execute it in a view in order to save it to attach it to a refreshable spreadsheet it fails.

The code is -

SELECT     MAX(WK.[TRASWEEK]) AS TRASWEEK
FROM         (SELECT DISTINCT [TRANS-WEEK] AS 'TRASWEEK'
                       FROM          dbo.[IH_RE-TNCY-TRANS] AS TRA6
                       WHERE      ([TRANS-DATE] > GETDATE() - 42) AND ([ACCOUNT-TYPE] = 'IN')
                       GROUP BY [TRANS-WEEK]) AS WK


When I run this in New Query. I get one result (correctly) of 27. 27 being the maximum week.

When I paste this in the view and execute it it changes the code to -

SELECT     MAX('TRASWEEK') AS Expr1
FROM         (SELECT DISTINCT [TRANS-WEEK] AS 'TRASWEEK'
                       FROM          dbo.[IH_RE-TNCY-TRANS] AS TRA6
                       WHERE      ([TRANS-DATE] > GETDATE() - 42) AND ([ACCOUNT-TYPE] = 'IN')
                       GROUP BY [TRANS-WEEK]) AS WK


This pulls me back just a result of "Trasweek" and not the 27 I would have hoped for. Why is 2012 doing this. Why is it changing my code?

Thanks

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 11/08/2013 :  04:32:07  Show Profile  Reply with Quote
DOnt use view editor. Create the code using CREATE VIEW syntax in SSMS editor itself.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000