4 Replies - 1362 Views - Last Post: 16 October 2007 - 03:11 PM Rate Topic: -----

#1 James Bond C++ Spy   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 132
  • Joined: 03-October 07

SQL Question Need Help

Posted 16 October 2007 - 01:05 PM

I have a question on how to do a query with SQL. The question is as follows:

Enter the SQL to show the names of all the measurement descriptions? NO PROBLEM

Change the heading in the query to Measurement Description. :blink:

Display the descriptions in alphabetical order. NO PROBLEM

Here is my sql:

select measurementdescriptions from measurements
????????
order by Measurement Description

Any help would be helpful

James Bond C++ Spy
:ph34r:

Is This A Good Question/Topic? 0
  • +

Replies To: SQL Question Need Help

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: SQL Question Need Help

Posted 16 October 2007 - 01:13 PM

Here you go, to change the column heading you use the AS keyword, which is a Reserved keyword in Transact-SQL, like so

select   measurementdescriptions AS 'Measurement Description'
FROM measurements ORDER BY Measurement Description


NOTE: The single quotes ' is only required if theres a space between the 2 words, but I always use them that way I don't forget to use it when its required.
Was This Post Helpful? 0
  • +
  • -

#3 aceofspades686   User is offline

  • D.I.C Regular
  • member icon

Reputation: 6
  • View blog
  • Posts: 334
  • Joined: 08-October 07

Re: SQL Question Need Help

Posted 16 October 2007 - 01:18 PM

Just a guess, but its probably meaning to add a header at the top of the outputted column that says "Measurement Description".

My SQL is a little rusty, but something like this should accomplish it.
SELECT measurementdescriptions "Measurement Description"
FROM measurements ORDER BY measurementdescriptions;


EDIT:Yeah, don't mind me, PsychoCoder's code it correct >.> Marking this out to avoid confusion.

This post has been edited by aceofspades686: 16 October 2007 - 03:32 PM

Was This Post Helpful? 0
  • +
  • -

#4 James Bond C++ Spy   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 132
  • Joined: 03-October 07

Re: SQL Question Need Help

Posted 16 October 2007 - 01:20 PM

Thanks for the super fast reply. :^: I did run your sql and received this error:

Server: Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near 'Description'.

James Bond C++ Spy
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: SQL Question Need Help

Posted 16 October 2007 - 03:11 PM

View Postaceofspades686, on 16 Oct, 2007 - 01:18 PM, said:

Just a guess, but its probably meaning to add a header at the top of the outputted column that says "Measurement Description".

My SQL is a little rusty, but something like this should accomplish it.
SELECT measurementdescriptions "Measurement Description"
FROM measurements ORDER BY measurementdescriptions;


Actually the code I gave is the correct way of doing it. You dont use double quotes " in SQL, and you hafve to have the AS statement as well.

select measurementdescriptions AS 'Measurement Description'
FROM measurements ORDER BY Measurement Description


EDIT: You can use double quotes "" if you use SET QUOTED_IDENTIFIER ON

This post has been edited by PsychoCoder: 18 October 2007 - 12:50 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1