Welcome to Dream.In.Code
Become an Expert!

Join 149,585 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,777 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: 81


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

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,482



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

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: 261


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: 81


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

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,482



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

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: 1/7/09 10:57PM

Be Social

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

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month