Re: Sql Query Problem with Sql Server

  • From: "Ricks Place" <OFBGMail@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Thu, 12 Jun 2008 12:40:19 -0400

Thanks Rod:
Just a bad DataBase Design. I am normalizing it some to fix the problem instead 
of messing with illogical workaround. 
It requires a Parent, Child design to eliminate duplactes if I want to bind 
directly to a GridView. I might work around it by selecting distinct 
PortfolioNames and using an array to  select desired rows into a table and then 
bind at runtime but I wanted to use Templating so will not be able to do that 
as far as I know. So I will just normalize the DB some.
Rick Farmington Mich. USA
  ----- Original Message ----- 
  From: Rodney Haynie 
  To: programmingblind@xxxxxxxxxxxxx 
  Sent: Thursday, June 12, 2008 10:16 AM
  Subject: RE: Sql Query Problem with Sql Server

  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 


  Select * From UserPortfolios  
  Where UserId = 'Richard';






  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: