SQL Statement modification for Excel Column Heading

At the bottom of this post is a SQL statement that returns data to an Excel spreadsheet.  

Some of the column headings that are displayed in Excel need to be changed.  Specifically:
1) User_Date_1           to    1st Curt Date
2) User_Numeric_1    to     1st Curt Amt
3) User_Date_2           to     2nd Curt Date
4) User_Numeric_2    to     2nd Curt Amt
5) User_Date_3           to     3rd Curt Date
6) User_Numeric_3    to     3rd Curt Amt

I'm new to SQL and it's syntax.  I've tried (on line 20) the following change:
vdd.User_Date_1 as 1st Curt Date

This results in a syntax error.  I don't know what the "vdd" at the start of that line means, cut am assuming this might be the reason for the syntax error.

Please advise.

SELECT
 vdd.Stock_No,
 VhStock.BR,
 VhStock.MAKE,
 VhStock.MODEL,
 VhStock.model_name,
 'Status' =
 case VhStock.USAGE
    when 'D' then 'Demo'
    when 'O' then 'On-Hold'
    when 'L' then 'On-Loan'
    when 'R' then 'Rental'
    when 'G' then 'Sold not Invoiced'
    when 'A' then 'Asset'
    when 'I' then 'Invoiced'
    when 'S' then 'Stock'
    Else if VhStock.Stock_Status = 'P' then 'Pending' else 'In-Stock' endif
 end,
 VhStock.FLOORVAL as FloorPlan,
 vdd.User_Date_1,
 vdd.User_Numeric_1,
 vdd.User_Date_2,
 vdd.User_Numeric_2,
 vdd.User_Date_3,
 vdd.User_Numeric_3
FROM
 Administrator.VhStock VhStock
LEFT JOIN VhStock_DealerDefined vdd ON (vdd.Stock_No = VhStock.NO)
WHERE (MONTH(vdd.User_Date_1) = 8 AND YEAR(vdd.User_Date_1) = 2015)
OR (MONTH(vdd.User_Date_2) = 8 AND YEAR(vdd.User_Date_2) = 2015)
OR (MONTH(vdd.User_Date_3) = 8 AND YEAR(vdd.User_Date_3) = 2015);
baleman2Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Data DudeCommented:
>I've tried (on line 20) the following change:
 vdd.User_Date_1 as 1st Curt Date
Try [Curt Date].  The use of any punctuation other than underscore _ or dash - (I think) forces the use of square brackets around the name.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
baleman2Author Commented:
So, modifications were made as shown below with interesting results.  

The column headings in Excel did indeed change as needed.  However, the data now displayed in the columns themselves has changed:
1) 1st Curt Date should be the date a payment is to be made toward purchasing a piece of equipment
2) 1st Curt Amt should be the amount of the payment to be made on the 1st Curt Date
3) 2nd Curt Date should be the date a payment is to be made toward purchasing a piece of equipment
4) 2nd Curt Amt should be the amount of the payment to be made on the 2nd Curt Date
5) 3rd Curt Date should be the date a payment is to be made toward purchasing a piece of equipment
4) 3rd Curt Amt should be the amount of the payment to be made on the 3rd Curt Date

Both 1 and 2 (shown above) display an identical "amount" of money.  "1st Curt Date" column no longer displays a date; but, displays the payment as shown in the "1st Curt Amt" column.

Both 3 and 4 (shown above) display an identical "amount" of money.  "2nd Curt Date" column no longer displays a date; but, displays the payment as shown in the "2nd Curt Amt" column.

Both 5 and 6 (shown above) display an identical "amount" of money.  "3rd Curt Date" column no longer displays a date; but, displays the payment as shown in the "3rd Curt Amt" column.




SELECT
  vdd.Stock_No,
  VhStock.BR,
  VhStock.MAKE,
  VhStock.MODEL,
  VhStock.model_name,
  'Status' =
  case VhStock.USAGE
     when 'D' then 'Demo'
     when 'O' then 'On-Hold'
     when 'L' then 'On-Loan'
     when 'R' then 'Rental'
     when 'G' then 'Sold not Invoiced'
     when 'A' then 'Asset'
     when 'I' then 'Invoiced'
     when 'S' then 'Stock'
     Else if VhStock.Stock_Status = 'P' then 'Pending' else 'In-Stock' endif
  end,
  VhStock.FLOORVAL as FloorPlan,
  vdd.User_Date_1 as [1st Curt Date],
  vdd.User_Numeric_1 as [1st Curt Amt],
  vdd.User_Date_2 as [2nd Curt Date],
  vdd.User_Numeric_2 as [2nd Curt Amt],
  vdd.User_Date_3 as [3rd Curt Date],
  vdd.User_Numeric_3 as [3rd Curt Amt]
FROM
  Administrator.VhStock VhStock
LEFT JOIN VhStock_DealerDefined vdd ON (vdd.Stock_No = VhStock.NO)
WHERE (MONTH(vdd.User_Date_1) = 8 AND YEAR(vdd.User_Date_1) = 2015)
OR (MONTH(vdd.User_Date_2) = 8 AND YEAR(vdd.User_Date_2) = 2015)
OR (MONTH(vdd.User_Date_3) = 8 AND YEAR(vdd.User_Date_3) = 2015);
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.