Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Very Difficult query!
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
0 Posts

Posted - 01/08/2003 :  08:54:45  Show Profile  Visit AskSQLTeam's Homepage
Dan writes "Just wondering if I could pick your brain on a particular SQL query I'm battling with..... :-)

I'm not too sure if it is going to be possible....

I have a table with a list of the courses that we offer and I am wanting to generate a query that will return all the Subject areas eg COMP, ACCT, ECON etc

In the 'subject' Table I have a column called 'subjectCode' which stores the Code for each subject eg COMP101, COMP204, ACCT101

I don't know if it is possible to query the table and get a table of just the Subject Areas, but if it only returned one COMP code(say COMP101) and one ACCT Code(say ACCT101) I could then use ASP.NET to use only the first 4 letters from the returned rows.

actual table:

subjectCode
ACCT101
ACCT104
ACCT204
COMP104
COMP108
COMP204
ECON312
ECON101
ECON214
...

Returned query could look like this:
subjectCode
ACCT101
COMP104
ECON312
...

-or ideally
subjectCode
ACCT
COMP
ECON
...

I appreciate any help you may be able to give!"

nr
SQLTeam MVY

United Kingdom
12543 Posts

Posted - 01/08/2003 :  09:10:43  Show Profile  Visit nr's Homepage

select distinct left(subjectCode,4) from tbl

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

jsmith8858
Dr. Cross Join

USA
7423 Posts

Posted - 01/08/2003 :  09:24:10  Show Profile  Visit jsmith8858's Homepage
difficult query?

Nr didn't even break a sweat on that one!

- Jeff
Go to Top of Page

Peter Dutch
Posting Yak Master

Netherlands
127 Posts

Posted - 01/08/2003 :  09:33:33  Show Profile
and the fun thing is, he got the same anser YESTERDAY from the forums on asp.net.....

(would that be considered a crosspost too :) )

Go to Top of Page
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000