Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Problem

Status
Not open for further replies.

lah3233

MIS
Jul 15, 2003
33
US
Is there anyway in a select statment to list 5 fields but only display 3 of them? I need some of the fields for the order by clause but don't actually want them displayed. Is there a solution?
 
Just dont select them, or is that an over simplification ?

Select field1,field2,field3 ORDER BY field1,field2,field3,field4,field5
 
That's an oversimplification....it won't allow us to do the order by without selecting all the fields
 
My suggestion is a valid sql statement, whats IT in "it wont allow us" ?
 
You could create a view which has all 5 fields then use a select statement with the 3 you want from the view.
:)
 
What error are you getting? SonOfEmidec1100's solution is perfectly valid. ORDER BY columns don't necessarily have to appear in the SELECT list.

Are you using a GROUP BY? If so, then you would have to include the ORDER BY items in that.

Can you post your actual query if you're still having problems.

--James
 
Here's the statement. There is a nested SQL statement in the order by:

SELECT (strLName + ', ' + strFName) as name
FROM UserInfo, LoginInfo
WHERE UserInfo.strUserID = LoginInfo.strUserID
AND strRights = 'user'
AND (strUserStatus = 'active'
OR strUserStatus = 'inactive')
ORDER BY (SELECT strLName + ', ' + strFName
FROM UserInfo
WHERE strAdminID = UserInfo.strUserID) ASC,
strLName, strFName, strUserStatus


What essentially we want to happen is just change the order by clause around depending on how the user clicks to sort the data. Does this make sense??

Thanks for all the helP!
 
I'm struggling to make sense of this to be honest. Can you describe the tables you are using, the relationships between them and what results you want to see?

--James
 
It's somewhat complicated....but I think we are going to try using views and see where we can get from there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top