RE: Sql Query Problem with Sql Server

  • From: Rodney Haynie <RodneyH@xxxxxxxxxx>
  • To: "programmingblind@xxxxxxxxxxxxx" <programmingblind@xxxxxxxxxxxxx>
  • Date: Thu, 12 Jun 2008 10:16:09 -0400

Is it possible for a user to have the same PortfolioName more than once?  If 
not, then there is no reason for a distinct, and the following will work for 
you.

Select * From UserPortfolios
Where UserId = 'Richard';


HTH.
-Rodney


From: programmingblind-bounce@xxxxxxxxxxxxx 
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Ricks Place
Sent: Thursday, June 12, 2008 7:37 AM
To: programmingblind@xxxxxxxxxxxxx
Subject: Sql Query Problem with Sql Server

Hi Guys: I have a Sql Server table with about 40 columns.
I want to select the rows, all columns, where 1 of the columns comprise a 
distinct constraint.
I  Created strSelect:
Select Distinct PortfolioName From UserPortfolios
Where UserId = 'Richard';
It only returns the field specified but a GridView bind expects an entire 
table, about 40 fields so fails.
So I think I need to select the distinct field, PortfolioName,  then select the 
entire row for each distinct PortfolioName in the first select.
A subquery, according to what I'm reading only  returns one column.  Do I need 
to use a join or  would it be called something else?
For Example:
I was thinking of:
Select Distinct PortfolioName, PortfolioPrimaryKey From UserPortfolios
Select * from UserPortfolios where PortfolioPrimaryKey = the selected key in 
the above statement
How would you handle something like this? Am I on the right track ro could you 
suggest something I can use or research more?
Rick Farmington Mich. USA

Other related posts: