Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become an Expert!

Join 244,281 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,150 people online right now. Registration is fast and FREE... Join Now!




SQL Question Need Help

 
Reply to this topicStart new topic

SQL Question Need Help

James Bond C++ Spy
16 Oct, 2007 - 12:05 PM
Post #1

D.I.C Head
**

Joined: 3 Oct, 2007
Posts: 89



Thanked: 1 times
My Contributions
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.gif

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.gif

User is offlineProfile CardPM
+Quote Post


PsychoCoder
RE: SQL Question Need Help
16 Oct, 2007 - 12:13 PM
Post #2

loves.Coding(this);
Group Icon

Joined: 26 Jul, 2007
Posts: 12,283



Thanked: 372 times
Dream Kudos: 10775
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

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

SQL
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.
User is offlineProfile CardPM
+Quote Post

aceofspades686
RE: SQL Question Need Help
16 Oct, 2007 - 12:18 PM
Post #3

D.I.C Regular
Group Icon

Joined: 8 Oct, 2007
Posts: 315



Thanked: 4 times
Dream Kudos: 100
My Contributions
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 Oct, 2007 - 02:32 PM
User is offlineProfile CardPM
+Quote Post

James Bond C++ Spy
RE: SQL Question Need Help
16 Oct, 2007 - 12:20 PM
Post #4

D.I.C Head
**

Joined: 3 Oct, 2007
Posts: 89



Thanked: 1 times
My Contributions
Thanks for the super fast reply. icon_up.gif 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
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: SQL Question Need Help
16 Oct, 2007 - 02:11 PM
Post #5

loves.Coding(this);
Group Icon

Joined: 26 Jul, 2007
Posts: 12,283



Thanked: 372 times
Dream Kudos: 10775
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
QUOTE(aceofspades686 @ 16 Oct, 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.
SQL
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.

SQL
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 Oct, 2007 - 11:50 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 02:12PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month