troubleshooting Question

Select Field1 as @YYYY, ....  dynamic alias name

Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America asked on
Microsoft SQL Server 2008Microsoft SQL Server 2005Microsoft SQL Server
9 Comments2 Solutions377 ViewsLast Modified:
Question: How can I make this query take @LY and @YYYY as alias names?

Thank you.
ALTER PROCEDURE [dbo].[spAuunuaCountMedCtr]
	 @StatType_ID INT = NULL
	 ,@YYYY NVARCHAR(4) = NULL
	 ,@RegionID INT = NULL
AS
BEGIN

	DECLARE @LY NVARCHAR(4)
	SET @LY = CONVERT(Varchar(4),CONVERT(INT,@YYYY)-1)
	select @LY, @YYYY
	
	SELECT t.LastYearCount  as @LY, t.CurrYearCount as @YYYY, (t.IncreaseOverLastYear/100) as [%]  
	FROM...

END
ASKER CERTIFIED SOLUTION
Aneesh
Database Consultant
Join our community to see this answer!
Unlock 2 Answers and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros