Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2004
    Posts
    12

    Red face Unanswered: column name alias concatenation

    I have a web application where I would like to return a dynamic column name using aliasing. below is an example:

    select hours as 'Fri<BR>' + cast(Day(getDate()) as varchar(2)) from todayshours

    I get an error trying to do concatenation as part of the alais. Any ideas?

    Luke
    lgraunke AT 4invie.com

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Whats <BR>

    Is this being done in SQL Server?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Feb 2004
    Posts
    12
    Ideally I would like the column name/header to show something like 'Fri<BR>20'. The '<BR>' is just some web formating that is automatically incorporated.

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    This should float your boat...
    Code:
    USE Northwind
    GO
    
    DECLARE @cmd varchar(8000)
    
    SELECT @cmd = 'SELECT Quantity AS ['
    	+ CASE DATEPART(WeekDay,GetDate())
    		WHEN 1 THEN 'SUNDAY'
    		WHEN 2 THEN 'MONDAY'
    		WHEN 3 THEN 'TUESDAY'
    		WHEN 4 THEN 'WEDNESDAY'
    		WHEN 5 THEN 'THURSDAY'
    		WHEN 6 THEN 'FRIDAY'
    		WHEN 7 THEN 'SATURDAY'
    	  END
    	+ '<BR>' 
    	+ cast(Day(getDate()) as varchar(2))
    	+ '] FROM [Order Details]'
    
    SELECT @cmd
    
    EXEC(@cmd)
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  5. #5
    Join Date
    Feb 2004
    Posts
    12
    Thanks, that was exactly what I was looking for.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •