Click here to Skip to main content
15,889,992 members
Home / Discussions / Database
   

Database

 
AnswerRe: Is it possible to pass datepart abbreviations to a function? Pin
PIEBALDconsult20-Apr-11 3:02
mvePIEBALDconsult20-Apr-11 3:02 
GeneralRe: Is it possible to pass datepart abbreviations to a function? Pin
J4amieC20-Apr-11 3:18
J4amieC20-Apr-11 3:18 
GeneralRe: Is it possible to pass datepart abbreviations to a function? Pin
PIEBALDconsult20-Apr-11 14:50
mvePIEBALDconsult20-Apr-11 14:50 
AnswerRe: Is it possible to pass datepart abbreviations to a function? Pin
jschell20-Apr-11 8:08
jschell20-Apr-11 8:08 
QuestionUsing the same table more than once in a SQL View Pin
Etienne_12319-Apr-11 20:53
Etienne_12319-Apr-11 20:53 
AnswerRe: Using the same table more than once in a SQL View Pin
loveangel88819-Apr-11 21:13
loveangel88819-Apr-11 21:13 
AnswerRe: Using the same table more than once in a SQL View Pin
Wayne Gaylard19-Apr-11 21:20
professionalWayne Gaylard19-Apr-11 21:20 
GeneralRe: Using the same table more than once in a SQL View [modified] Pin
Etienne_12319-Apr-11 23:37
Etienne_12319-Apr-11 23:37 
I have a MandateFeature table that contains two Id's , MandateId and FeatureId. Each of these are foreign keys from two different tables (Feature and Mandate). If a mandate (house) contains 3 bedrooms and the Id for bedroom is 5, then the entries in the MandateFeature table will look something like this:

MandateId | FeatureId
----------------------
2, 5
2, 5
2, 5

If a mandate (house) has 2 bathrooms and the Id for bathroom is 6, then the table would look something like this:

MandateId | FeatureId
----------------------
2, 5
2, 5
2, 5
2, 6
2, 6


What I want to do, is to count the number of bedrooms as well as the number of bathrooms and then display it as follows:
Bedrooms: 3
Bathroom: 2

So I get it working using this:

SELECT DISTINCT dbo.__Mandate.Id, COUNT(BedroomFeature.FeatureId) AS Bedrooms, dbo.__MandateType.MandateType, dbo.__Mandate.ErfSize
FROM         dbo.__Mandate INNER JOIN
                      dbo.__MandateType ON dbo.__Mandate.MandateTypeId = dbo.__MandateType.Id LEFT OUTER JOIN
                      dbo.__MandateListing ON dbo.__Mandate.Id = dbo.__MandateListing.MandateId LEFT OUTER JOIN
                      dbo.__MandateFeature AS BedroomFeature ON dbo.__Mandate.Id = BedroomFeature.MandateId AND BedroomFeature.FeatureId =
                          (SELECT     Id
                            FROM          dbo.__Feature AS __Feature_1
                            WHERE      (Feature = 'Bedroom')) LEFT OUTER JOIN
                      dbo.__Feature ON BedroomFeature.FeatureId = dbo.__Feature.Id
GROUP BY dbo.__Mandate.Id, dbo.__MandateType.MandateType, dbo.__Mandate.ErfSize


..but this of course only displays the number of bedrooms. As soon as I duplicate this part:

LEFT OUTER JOIN
                      dbo.__MandateFeature AS BedroomFeature ON dbo.__Mandate.Id = BedroomFeature.MandateId AND BedroomFeature.FeatureId =
                          (SELECT     Id
                            FROM          dbo.__Feature AS __Feature_1
                            WHERE      (Feature = 'Bedroom')) LEFT OUTER JOIN
                      dbo.__Feature ON BedroomFeature.FeatureId = dbo.__Feature.Id


and modify it to this:

LEFT OUTER JOIN
                      dbo.__MandateFeature AS BathroomFeature ON dbo.__Mandate.Id = BathroomFeature.MandateId AND BathroomFeature.FeatureId =
                          (SELECT     Id
                            FROM          dbo.__Feature AS __Feature_2
                            WHERE      (Feature = 'Bathroom')) LEFT OUTER JOIN
                      dbo.__Feature AS __Feature_2 ON BathroomFeature.FeatureId = dbo.__Feature.Id


..and add COUNT(BathroomFeature.FeatureId) AS Bathrooms to the SELECT, it displays the bedrooms and bathrooms, but the values are duplicated across these 2 columns (and it's not the correct values either)

modified on Wednesday, April 20, 2011 5:49 AM

AnswerRe: Using the same table more than once in a SQL View Pin
Mycroft Holmes20-Apr-11 12:52
professionalMycroft Holmes20-Apr-11 12:52 
QuestionCan't update table with expression field Pin
Muammar©19-Apr-11 7:48
Muammar©19-Apr-11 7:48 
AnswerRe: Can't update table with expression field Pin
Luc Pattyn19-Apr-11 7:55
sitebuilderLuc Pattyn19-Apr-11 7:55 
GeneralRe: Can't update table with expression field Pin
Muammar©19-Apr-11 20:26
Muammar©19-Apr-11 20:26 
AnswerRe: Can't update table with expression field Pin
Mycroft Holmes19-Apr-11 12:51
professionalMycroft Holmes19-Apr-11 12:51 
GeneralRe: Can't update table with expression field Pin
Muammar©19-Apr-11 20:43
Muammar©19-Apr-11 20:43 
QuestionDelete query stuck in suspended status Pin
wizardzz19-Apr-11 6:21
wizardzz19-Apr-11 6:21 
AnswerRe: Delete query stuck in suspended status Pin
wizardzz19-Apr-11 6:36
wizardzz19-Apr-11 6:36 
JokeRe: Delete query stuck in suspended status Pin
Chris Meech19-Apr-11 8:17
Chris Meech19-Apr-11 8:17 
GeneralRe: Delete query stuck in suspended status Pin
wizardzz19-Apr-11 8:35
wizardzz19-Apr-11 8:35 
QuestionPerformance question Pin
Johnny J.18-Apr-11 22:46
professionalJohnny J.18-Apr-11 22:46 
AnswerRe: Performance question Pin
PIEBALDconsult19-Apr-11 2:42
mvePIEBALDconsult19-Apr-11 2:42 
AnswerSQL Profiler Pin
David Mujica19-Apr-11 3:32
David Mujica19-Apr-11 3:32 
AnswerRe: Performance question Pin
dasblinkenlight19-Apr-11 5:20
dasblinkenlight19-Apr-11 5:20 
AnswerRe: Performance question Pin
SilimSayo4-May-11 10:05
SilimSayo4-May-11 10:05 
QuestionORA-01033: ORACLE initialization or shutdown in progress Pin
Ish Kapila18-Apr-11 5:47
Ish Kapila18-Apr-11 5:47 
AnswerRe: ORA-01033: ORACLE initialization or shutdown in progress Pin
Om Prakash Pant18-Apr-11 20:48
Om Prakash Pant18-Apr-11 20:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.