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

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Very Difficult query!

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-01-08 : 08:54:45
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

12543 Posts

Posted - 2003-01-08 : 09:10:43

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

7423 Posts

Posted - 2003-01-08 : 09:24:10
difficult query?

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

- Jeff
Go to Top of Page

Peter Dutch
Posting Yak Master

127 Posts

Posted - 2003-01-08 : 09:33:33
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
   

- Advertisement -