Showing posts with label rows. Show all posts
Showing posts with label rows. Show all posts

Friday, March 30, 2012

Help ordering IN clause using passed order

I am trying to make the IN clause of a stored procedure return the rows in
the order in which the IN clause values were specified. What I have is a
table that can be sorted on a number of columns yet I want to pull back a
subset of rows. I have the set of rows needed but I am unable to return the
rows in the correct order using the IN clause.
For example:
SELECT
T.ID,
T.Name
FROM
MyTable
WHERE
T.ID IN ('1,3,2')
Notice that the ID order is 1,3,2. I want the rows in that order without
having to use an Order By on the correct column. That would require that I
a) use dynamic SQL just to use the correct order by column or b) provide the
same query a bunch of times just changing the sorting. I would prefer to not
do either.
Is this possible in SQL Server?One option is to use a CASE expression like:
ORDER BY CASE id WHEN 1 THEN 1
WHEN 3 THEN 2
WHEN 2 THEN 3
END ;
For a general option, use CHARINDEX or PATINDEX function like:
ORDER BY CHARINDEX( ',' + @.list + ',', ',' + id + ',' ) ;
Anith|||Tim Menninger wrote:
> I am trying to make the IN clause of a stored procedure return the rows in
> the order in which the IN clause values were specified. What I have is a
> table that can be sorted on a number of columns yet I want to pull back a
> subset of rows. I have the set of rows needed but I am unable to return th
e
> rows in the correct order using the IN clause.
> For example:
> SELECT
> T.ID,
> T.Name
> FROM
> MyTable
> WHERE
> T.ID IN ('1,3,2')
> Notice that the ID order is 1,3,2. I want the rows in that order without
> having to use an Order By on the correct column. That would require that I
> a) use dynamic SQL just to use the correct order by column or b) provide t
he
> same query a bunch of times just changing the sorting. I would prefer to n
ot
> do either.
> Is this possible in SQL Server?
You should know that you cannot reliably order any query without using
ORDER BY. Try:
DECLARE @.in VARCHAR(100)
SET @.in = '1,3,2'
SELECT T.id, T.name
FROM MyTable
WHERE CHARINDEX(','+CAST(id AS VARCHAR)+',',','+@.in+',')>0
ORDER BY CHARINDEX(','+CAST(id AS VARCHAR)+',',','+@.in+',');
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||I'd try to modify Erland Sommarskog's UDF iter_charlist_to_table that
parses a comma-separated string, found at
http://www.sommarskog.se/arrays-in-sql.html
CREATE FUNCTION iter_charlist_to_int_table
(@.list ntext,
@.delimiter nchar(1) = N',')
RETURNS @.tbl TABLE (listpos int IDENTITY(1, 1) NOT NULL,
value int,
nstr nvarchar(2000)) AS
BEGIN
DECLARE @.pos int,
@.textpos int,
@.chunklen smallint,
@.tmpstr nvarchar(4000),
@.leftover nvarchar(4000),
@.tmpval nvarchar(4000)
SET @.textpos = 1
SET @.leftover = ''
WHILE @.textpos <= datalength(@.list) / 2
BEGIN
SET @.chunklen = 4000 - datalength(@.leftover) / 2
SET @.tmpstr = @.leftover + substring(@.list, @.textpos,
@.chunklen)
SET @.textpos = @.textpos + @.chunklen
SET @.pos = charindex(@.delimiter, @.tmpstr)
WHILE @.pos > 0
BEGIN
SET @.tmpval = ltrim(rtrim(left(@.tmpstr, @.pos - 1)))
INSERT @.tbl (value, nstr) VALUES(cast(@.tmpval as int),
@.tmpval)
SET @.tmpstr = substring(@.tmpstr, @.pos + 1, len(@.tmpstr))
SET @.pos = charindex(@.delimiter, @.tmpstr)
END
SET @.leftover = @.tmpstr
END
INSERT @.tbl(value, nstr) VALUES (cast(ltrim(rtrim(@.leftover)) as
int), ltrim(rtrim(@.leftover)))
RETURN
END
create table #t(i int)
insert into #t values(1)
insert into #t values(2)
insert into #t values(3)
insert into #t values(4)
insert into #t values(5)
select #t.i from #t, dbo.iter_charlist_to_int_table('1,3,2', ',') t
where #t.i=t.value
order by t.listpos
i
--
1
3
2
(3 row(s) affected)|||Your IN clause has only one member. You are confusing IN (1,3,2) and IN
('1,3,2'). You probably need to use dynamic SQL anyway to get your query
working the way you want it.
For example, with this:
create table fred
(
ID varchar(2),
Name varchar(100)
)
go
insert into fred(ID,Name)
select '1','Jim' union
select '2','Tom' union
select '3','Appleby'
select id,name from fred where id in ('1,2')
The select doesn't return anything. If ID were an int, you would get a
syntax error in the select statement
"Tim Menninger" <tmenninger@.comcast.net> wrote in message
news:e77bacLMGHA.1124@.TK2MSFTNGP10.phx.gbl...
>I am trying to make the IN clause of a stored procedure return the rows in
>the order in which the IN clause values were specified. What I have is a
>table that can be sorted on a number of columns yet I want to pull back a
>subset of rows. I have the set of rows needed but I am unable to return the
>rows in the correct order using the IN clause.
> For example:
> SELECT
> T.ID,
> T.Name
> FROM
> MyTable
> WHERE
> T.ID IN ('1,3,2')
> Notice that the ID order is 1,3,2. I want the rows in that order without
> having to use an Order By on the correct column. That would require that I
> a) use dynamic SQL just to use the correct order by column or b) provide
> the same query a bunch of times just changing the sorting. I would prefer
> to not do either.
> Is this possible in SQL Server?
>|||Someone was asleep in RDBMS 101 class! What is the definition of a
table? It models a set of rows. By definition a set has no ordering.
This is what you should have learned the first w in class.
Do this in the front end, where all formatting and presentation is done
in a tiered architecture (w #2) or with an ORDER BY clause to
convert from a tale to a cursor.sql

Help on Updategram

I am recieveing this error.
"Ambiguous delete, unique identifier required
Transaction aborted"
I am trying to delete several rows where a column equals
a certain value like "7". THe errors occurs because
SQLXML appears to only allow from a single row to be
deleted at a time. Here is what the Profiler shows:
SET XACT_ABORT ON
BEGIN TRAN
DECLARE @.eip INT, @.r__ int, @.e__ int
SET @.eip = 0
DELETE tblNote WHERE ( pkAccountID=6 ) ; SELECT @.e__ =
@.@.ERROR, @.r__ = @.@.ROWCOUNT
IF (@.e__ != 0 OR @.r__ != 1) SET @.eip = 1
IF (@.r__ > 1) RAISERROR ( N'SQLOLEDB Error Description:
Ambiguous delete, unique identifier required Transaction
aborted ', 16, 1)
ELSE IF (@.r__ < 1) RAISERROR ( N'SQLOLEDB Error
Description: Empty delete, no deletable rows found
Transaction aborted ', 16, 1)
IF (@.eip != 0) ROLLBACK ELSE COMMIT
SET XACT_ABORT OFF
WHY?!?!?!?!?!?!
Regards,
Ron
To delete multiple rows in an Updategram, you have to specify each row to be
deleted individually in the "before" element - there's no equivalent of a
wildcard delete.
From SQLXML 3.0 BOL:
"If an element that is specified in the updategram either matches more than
one row in the table or does not match any table row, the updategram returns
an error and cancels the entire <sync> block. Only one record at a time can
be deleted by an element in the updategram."
Hope that helps,
Graeme
--
Graeme Malcolm
Principal Technologist
Content Master Ltd.
www.contentmaster.com
"Ron Antinori" <rantinori@.bluestoneinfo.com> wrote in message
news:264601c48e1c$9a727f80$a301280a@.phx.gbl...
I am recieveing this error.
"Ambiguous delete, unique identifier required
Transaction aborted"
I am trying to delete several rows where a column equals
a certain value like "7". THe errors occurs because
SQLXML appears to only allow from a single row to be
deleted at a time. Here is what the Profiler shows:
SET XACT_ABORT ON
BEGIN TRAN
DECLARE @.eip INT, @.r__ int, @.e__ int
SET @.eip = 0
DELETE tblNote WHERE ( pkAccountID=6 ) ; SELECT @.e__ =
@.@.ERROR, @.r__ = @.@.ROWCOUNT
IF (@.e__ != 0 OR @.r__ != 1) SET @.eip = 1
IF (@.r__ > 1) RAISERROR ( N'SQLOLEDB Error Description:
Ambiguous delete, unique identifier required Transaction
aborted ', 16, 1)
ELSE IF (@.r__ < 1) RAISERROR ( N'SQLOLEDB Error
Description: Empty delete, no deletable rows found
Transaction aborted ', 16, 1)
IF (@.eip != 0) ROLLBACK ELSE COMMIT
SET XACT_ABORT OFF
WHY?!?!?!?!?!?!
Regards,
Ron

Wednesday, March 28, 2012

help on sql select

i got a table as following
product_id product_name product_description product_price

there are about 50 rows in this table, my qeustion is how to write an SQL statement that return product_name, description and price( or every colume) for the the lowest product_price in this table.
i know this sql will return the lowest price(select min(product_price) from product), but it doesn't return other information about it.

i also try the following statement, but didn't work
select * from product where min(product_price)

what is the sql statement to perform this requirement?

Hi,

very simple one is just to write

select * from product where product_price = (

select min(product_price) FROM product

)

Or even simpler

select top 1 * from product order by product_price ASC

|||problem solved, that's simple.
thanx

Monday, March 26, 2012

help on query

Hi,
My table has a column [account type], some rows have null value, when I
query it to eliminate some account type like accout != 'A', all the rows wit
h
null account won't showup either. I would like all the accounts other than
'A' show. How can I write it? ThanksYou could:
select * from TheTable
where isnull( [account type], ''') <> 'A'
Bryce|||...
Where account type Is Null OR account type <> 'A'
"Jen" wrote:

> Hi,
> My table has a column [account type], some rows have null value, when I
> query it to eliminate some account type like accout != 'A', all the rows w
ith
> null account won't showup either. I would like all the accounts other than
> 'A' show. How can I write it? Thanks|||Try,
select * from your_table
where [account] != 'A' or [account] is null
AMB
"Jen" wrote:

> Hi,
> My table has a column [account type], some rows have null value, when I
> query it to eliminate some account type like accout != 'A', all the rows w
ith
> null account won't showup either. I would like all the accounts other than
> 'A' show. How can I write it? Thanks

Wednesday, March 21, 2012

Help obtain a window of rows from a table

Hi,
I have a client program in vb.net that access a SQL server database. Each
time the client program need some data it retrieve the whole table, so it is
pretty slow.
I wonder if it is possible, for the client, to retrieve only a window of
rows around the actual value he is using. That is, if he is actually in row
4000 he will retrieve from row 3000 to 5000 but not the complete table. If
this is possible what I need is something like:
1) The client send SQL-Server a string with the actual ordering and the ID
of the actual row.
2) SQL-Server order the table following the order specified in the string
send by the client.
3) Using the ordered table SQL-Server "find" the ID of the actual row.
4) SQL-Server return a number of rows before and after the Id of the actual
row (no idea how to do this).
Any help.
Thanks,
JamesHi James,
Yes - its basically paging.
The basics are this...
declare @.results table (
idrow int not null identity,
yourresultcol1...
yourresultcol2...
)
insert @.results ( yourresultscol1, yourresultscol2 )
select yourresultscol1, yourresultscol2
from table...
where ...
order by ...
select *
from @.results
where idrow between @.start and @.finish
I know its not a complete working example but does that give you enough
idea?
Tony
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"James" <info@.pricetech.es> wrote in message
news:OTkWPANHGHA.1628@.TK2MSFTNGP12.phx.gbl...
> Hi,
> I have a client program in vb.net that access a SQL server database. Each
> time the client program need some data it retrieve the whole table, so it
> is pretty slow.
> I wonder if it is possible, for the client, to retrieve only a window of
> rows around the actual value he is using. That is, if he is actually in
> row 4000 he will retrieve from row 3000 to 5000 but not the complete
> table. If this is possible what I need is something like:
> 1) The client send SQL-Server a string with the actual ordering and the ID
> of the actual row.
> 2) SQL-Server order the table following the order specified in the string
> send by the client.
> 3) Using the ordered table SQL-Server "find" the ID of the actual row.
> 4) SQL-Server return a number of rows before and after the Id of the
> actual row (no idea how to do this).
> Any help.
> Thanks,
> James
>
>|||Sorry, i forgot to mention, in SQL 2005 its a whole lot easier.
We have the rownumber() function and cte that does it all for us - there are
some really useful examples in bol.
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"Tony Rogerson" <tonyrogerson@.sqlserverfaq.com> wrote in message
news:uhnuUbNHGHA.1124@.TK2MSFTNGP10.phx.gbl...
> Hi James,
> Yes - its basically paging.
> The basics are this...
> declare @.results table (
> idrow int not null identity,
> yourresultcol1...
> yourresultcol2...
> )
> insert @.results ( yourresultscol1, yourresultscol2 )
> select yourresultscol1, yourresultscol2
> from table...
> where ...
> order by ...
> select *
> from @.results
> where idrow between @.start and @.finish
> I know its not a complete working example but does that give you enough
> idea?
> Tony
> --
> Tony Rogerson
> SQL Server MVP
> http://sqlserverfaq.com - free video tutorials
>
> "James" <info@.pricetech.es> wrote in message
> news:OTkWPANHGHA.1628@.TK2MSFTNGP12.phx.gbl...
>|||James
I think Tom Moreau had already answered the same or almost the same question
a few days ago. Pls search on internet
"James" <info@.pricetech.es> wrote in message
news:OTkWPANHGHA.1628@.TK2MSFTNGP12.phx.gbl...
> Hi,
> I have a client program in vb.net that access a SQL server database. Each
> time the client program need some data it retrieve the whole table, so it
> is pretty slow.
> I wonder if it is possible, for the client, to retrieve only a window of
> rows around the actual value he is using. That is, if he is actually in
> row 4000 he will retrieve from row 3000 to 5000 but not the complete
> table. If this is possible what I need is something like:
> 1) The client send SQL-Server a string with the actual ordering and the ID
> of the actual row.
> 2) SQL-Server order the table following the order specified in the string
> send by the client.
> 3) Using the ordered table SQL-Server "find" the ID of the actual row.
> 4) SQL-Server return a number of rows before and after the Id of the
> actual row (no idea how to do this).
> Any help.
> Thanks,
> James
>
>|||James wrote:
> Hi,
> I have a client program in vb.net that access a SQL server database. Each
> time the client program need some data it retrieve the whole table, so it
is
> pretty slow.
> I wonder if it is possible, for the client, to retrieve only a window of
> rows around the actual value he is using. That is, if he is actually in ro
w
> 4000 he will retrieve from row 3000 to 5000 but not the complete table. If
> this is possible what I need is something like:
> 1) The client send SQL-Server a string with the actual ordering and the ID
> of the actual row.
> 2) SQL-Server order the table following the order specified in the string
> send by the client.
> 3) Using the ordered table SQL-Server "find" the ID of the actual row.
> 4) SQL-Server return a number of rows before and after the Id of the actua
l
> row (no idea how to do this).
> Any help.
> Thanks,
> James
Take a look at:
http://www.aspfaq.com/show.asp?id=2120
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--

Monday, March 19, 2012

Help needed!

Hello guys,
I'm new to the forum and to MS SQL 2K.
I'm trying to a merge similar rows in a table into a single row and put them in a new table.

Example:-
This is my input table
TableA
ID A B C
--------
1 jk kl bj
2 sd we op
3 io po kl
1 ui gh ew
2 kl re op
1 qw kj nn

My output table should look like this
TableB
ID A1 B1 C1 A2 B2 C2 A3 B3 C3
----------------
1 jk kl bj ui gh ew qw kj nn
2 sd we op kl re op
3 io po kl

Please help me on how to create my output.
Thanks in advance,

Sid.You want help violating the rules of normalization? Should I buy you a carton of cigarettes while I'm at it? Neither activity is healthy.

Seriously, if you must do this it is important to know whether the number of records for an ID is fixed or not. If it can be any number then you are not going to be able to define the columns on your output table ahead of time and you are left with a messy dynamic query task. If there is a limit on the number of records per ID then your problem is merely a moderately difficult cross-tab query.|||normalization or not
this is a good exercise to displace data
kinda like playing scales before you actually play a song on an instrument

i will be working on this tonight|||I'll check this query today ...|||giving up

I don't understand to purpose of this query|||i now have a headache|||There's not much point in pursuing this without further clarification from coolhandsid, so save the Tylenol.|||I've got

Table1
ID | A | B | C
1 | 2 | 3 | 4
2 | 9 | 4 | 5
3 | 22| 53 94

I want this result

Table1
ID X Y Z
1 | 81 | April | NULL
Y | 12 | Dog | Sheep
12.3 | Cherry | Spain | 3|||I've got broccolli and I want lobster. I can't make one out of the other either.|||Remeber the MASH episode (when they used to be good) when they made the spam lamb for the turkish troops?|||Originally posted by blindman
You want help violating the rules of normalization? Should I buy you a carton of cigarettes while I'm at it? Neither activity is healthy.

I would not want you doing the first ... but you can certainly buy that carton of cigs for me ...|||Thanks for all your help :),

I figured it out , it can be down by a DTS package or a cross-tab query.

Sid.

Originally posted by Karolyn
I've got

Table1
ID | A | B | C
1 | 2 | 3 | 4
2 | 9 | 4 | 5
3 | 22| 53 94

I want this result

Table1
ID X Y Z
1 | 81 | April | NULL
Y | 12 | Dog | Sheep
12.3 | Cherry | Spain | 3

Help needed with insert Statement

Hi,

I am trying to insert the follows rows to my production database... and this the sample data

RowPlan PART_ID FUND_ID TOT_ACT1 TOT_ACT2 Number Num1170925 129602759 19765P471 BB4928.47 CT0.00 DV26.30 GL153.75 TF0.00 WD0.00 OT0.00 EB5108.52 205.0110 24.04 206.0720 24.79 2170925 129602759 35472P406 BB2663.64 CT325.00 DV87.46 GL26.42 TF530.92 WD0.00 OT0.00 EB3633.44 189.0450 14.09 254.6210 14.27 3170925 129602759 LOAN BB1506.88 CT0.00 DV25.48 GL0.00 TF-530.92 WD0.00 OT0.00 EB1001.44 1506.88 1.00 1001.44 1.00 4170925 148603737 19765L587 BB25.14 CT0.00 DV0.46 GL-0.45 TF0.00 WD0.00 OT0.00 EB25.15 5.3830 4.67 5.4790 4.59 5170925 148603737 19765P471 BB7.48 CT0.00 DV0.05 GL0.23 TF0.00 WD0.00 OT0.00 EB7.76 0.3110 24.04 0.3130 24.79 6170925 148603737 35472P208 BB12.53 CT0.00 DV0.28 GL0.09 TF0.00 WD0.00 OT0.00 EB12.90 0.9360 13.39 0.9570 13.48 7170925 148603737 35472P604 BB7.48 CT0.00 DV0.24 GL0.15 TF0.00 WD0.00 OT0.00 EB7.87 0.4720 15.85 0.4870 16.16 8170925 148603737 315805549 BB29.72 CT0.00 DV0.00 GL2.15 TF0.00 WD0.00 OT0.00 EB31.87 1.5320 19.40 1.5320 20.80 9170925 148603737 197199102 BB5.00 CT0.00 DV0.06 GL0.27 TF0.00 WD0.00 OT0.00 EB5.33 0.1650 30.32 0.1670 31.94

So the number of rows in this table is 1007 right now my insert query inserts all the data but excepts LOAN and i want Loans inserted in a seperate column in my production dataabse but thats not happening so can some one pls take a look at this query and see whats wrong... My query is as follows

1INSERT INTO Statements..ParticipantPlanFundBalances12(3PlanId,4ParticipantId,5PeriodId,6FundId,7 Loans,8--PortfolioId,9Act1,10TotAct1,11Act2,12TotAct2,13Act3,14TotAct3,15Act4,16TotAct4,17Act5,18TotAct5,19Act6,20TotAct6,21Act7,22TotAct7,23Act8,24TotAct8,25Act9,26TotAct9,27Act10,28TotAct10,29Act11,30TotAct11,31Act12,32TotAct12,33Act13,34TotAct13,35Act14,36TotAct14,37Act15,38TotAct15,39Act16,40TotAct16,41Act17,42TotAct17,43Act18,44TotAct18,45Act19,46TotAct19,47Act20,48TotAct20,49OpeningUnits,50OPricePerUnit,51ClosingUnits,52CPricePerUnit,53AllocationPercent54)55SELECT56cp.PlanId,57p.ParticipantId,58@.PeriodId,59CaseWhen a.FUND_ID <>'LOAN'Then f.FundIdELSE 0END,60CASEWhen a.FUND_ID ='LOAN'Then'LOAN'END as Loanfunds,61--planinfo.PortfolioId,62CaseWHEN a.ACT_ID1 ='BB'Then 1END,63a.TOT_ACT1,64CaseWHEN a.ACT_ID2 ='CT'Then 2END,65a.TOT_ACT2,66CASEWhen a.ACT_ID3 ='DV'then 3END,67a.TOT_ACT3,68CASEWhen a.ACT_ID4 ='GL'Then 4End,69a.TOT_ACT4,70CAseWhen a.ACT_ID5 ='TF'THEN 5END,71 a.TOT_ACT5,72CASEWhen a.ACT_ID6 ='WD'THEN 6END,73a.TOT_ACT6,74CASEWHEN a.ACT_ID7 ='OT'THEN 7END,75a.TOT_ACT7,76CASEWhen a.ACT_ID8 ='EB'THEN 8END,77a.TOT_ACT8,78a.ACT_ID9,79a.TOT_ACT9,80a.ACT_ID10,81a.TOT_ACT10,82a.ACT_ID11,83a.TOT_ACT11,84a.ACT_ID12,85a.TOT_ACT12,86a.ACT_ID13,87a.TOT_ACT13,88a.ACT_ID14,89a.TOT_ACT14,90a.ACT_ID15,91a.TOT_ACT15,92a.ACT_ID16,93a.TOT_ACT16,94a.ACT_ID17,95a.TOT_ACT17,96a.ACT_ID18,97a.TOT_ACT18,98a.ACT_ID19,99a.TOT_ACT19,100a.ACT_ID20,101a.TOT_ACT20,102a.UNIT_OP,103a.PRICE_OP,104a.UNIT_CL,105a.PRICE_CL,106IsNull(i.ALLOC_PER1,'0.00')107FROM108ASDBF a109110--Derive the unique Plan Id111INNERJOIN Statements..ClientPlan cp112ONa.PLAN_NUM = cp.ClientPlanId113AND114cp.ClientId = @.ClientId115--Derive the unique ParticipantId from the Participant table116INNERJOIN Statements..Participant p117ONa.PART_ID = p.PartId118-- Derive the unique fund id from the Fund Table119INNERJOIN Statements..Fund f120ONa.FUND_ID = f.Cusip121OR122a.FUND_ID = f.Ticker123OR124a.FUND_ID = f.ClientFundId125LeftOuter JOIN INVSRC i126ONa.FUND_ID = i.INV_ID127AND128a.PLAN_NUM = i.Plan_Number129AND130a.PART_ID = i.PART_ID131--Get the unique portfolio name ffor the PArticipant Funds..132WHERE133--Ignore rows that failed the scrub.134a.Import = 1135AND136--Import only those that are not already in the ParticipantPlanFundBalances table137NOT EXISTS (138SELECT *139FROM140Statements..ParticipantPlanFundBalances1 pfb141WHERE142pfb.PlanId = cp.PlanId143AND144pfb.ParticipantId = p.ParticipantId145AND146pfb.PeriodId = @.PeriodId147AND148pfb.FundId = f.FundId149)

any help is appreciated.

Regards

Karen

Is there any error msg? Also can you explain this:

INNERJOIN Statements..Fund f ON a.FUND_ID = f.Cusip OR a.FUND_ID = f.Ticker ORa.FUND_ID = f.ClientFundId

|||

Thanks for your answer, no i am not getting any error message

INNERJOIN Statements..Fund f ON a.FUND_ID = f.Cusip OR a.FUND_ID = f.Ticker ORa.FUND_ID = f.ClientFundId
and this one means... i am getting the fundId from that table and inserting it to the PlanFundbalances..

for example in the sample data i have provided.. FUND_ID can be a 5 letter word saying DODGX,(Ticker) or some alphanumeric data whose length is and ClientFund(what ever the client wants and not in our database)

So fUND_ID 19765P471 will have a fundId of 15 or whatever..

But the word Loan isnt there in the Statements..Fund f table

Hope this helps.

Regards

Karen

|||

The way to debug would be to selectively comment out lines.. comment out the INSERT INTO line and just run the SELECT part. Start with the first ASDBF JOIN with ClientPlan and see if you get results. Then include the join with Participant and see if you get expected results..keep including each of the tables and see which part of the query is throwing you off. Otherwise there's really no way for us to tell what the issue is.. unless we see some sample data from each of the tables in the query and expected data into the final table...

|||

This is the first 10 rows of my final table..

1178241875271041NULLNULL1425.320020.000030.0000417.400050.000060.000070.00008442.720000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.00008.486050.12008.486052.170025.002178241875276204NULLNULL1120.090020.000034.040042.100050.000060.000070.00008126.230000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.00005.323022.56005.498022.96000.0031782418752710302NULLNULL1119.590020.000031.6900410.410050.000060.000070.00008131.690000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.00008.328014.36008.436015.610010.0041782418752711010NULLNULL1125.060020.000030.330048.830050.000060.000070.00008134.220000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.00004.344028.79004.355030.820010.0051782418752711024NULLNULL1126.850020.000030.7700410.070050.000060.000070.00008137.690000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.00003.003042.24003.020045.590010.0061782418752712040NULLNULL1121.380020.000030.0000410.520050.000060.000070.00008131.900000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.00005.340022.73005.340024.700010.0071782418752714449NULLNULL1123.490020.000030.000049.800050.000060.000070.00008133.290000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.00006.402019.29006.402020.820010.0081782418752714463NULLNULL1685.230020.000032.21004-75.820050.000060.000070.00008611.620000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000029.384023.320029.490020.740025.009178241875473493NULLNULL14320.20002110.0000349.35004-82.23005-210.800060.000070.000084186.520000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.0000443.55209.7400438.38009.550010.0010178241875473504NULLNULL14650.94002110.00003207.8800432.47005-648.680060.000070.000084352.610000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.0000305.180015.2400284.113015.320010.00

Suppose if PartID 18752 had loans i want the information to be displayed like in Line number 9

1178241875271041NULLNULL1425.320020.000030.0000417.400050.000060.000070.00008442.720000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.00008.486050.12008.486052.170025.002178241875276204NULLNULL1120.090020.000034.040042.100050.000060.000070.00008126.230000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.00005.323022.56005.498022.96000.0031782418752710302NULLNULL1119.590020.000031.6900410.410050.000060.000070.00008131.690000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.00008.328014.36008.436015.610010.0041782418752711010NULLNULL1125.060020.000030.330048.830050.000060.000070.00008134.220000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.00004.344028.79004.355030.820010.0051782418752711024NULLNULL1126.850020.000030.7700410.070050.000060.000070.00008137.690000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.00003.003042.24003.020045.590010.0061782418752712040NULLNULL1121.380020.000030.0000410.520050.000060.000070.00008131.900000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.00005.340022.73005.340024.700010.0071782418752714449NULLNULL1123.490020.000030.000049.800050.000060.000070.00008133.290000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.00006.402019.29006.402020.820010.0081782418752714463NULLNULL1685.230020.000032.21004-75.820050.000060.000070.00008611.620000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000029.384023.320029.490020.740025.00917824 18752 7 0 LOAN other columns10178241875473493NULLNULL14320.20002110.0000349.35004-82.23005-210.800060.000070.000084186.520000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.0000443.55209.7400438.38009.550010.0011178241875473504NULLNULL14650.94002110.00003207.8800432.47005-648.680060.000070.000084352.610000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.000000.0000305.180015.2400284.113015.320010.00

I will try debugging the sproc and see what i can acheive

Regards,

Karen

|||

ndinikar hit it spot on. Are there any records in the ASDBF table that have a FUND_ID ='LOAN'?

If not, that's your problem.

If yes, then one of the joins you have is filtering them out.

|||

Yes i do have 18 rows of Data where FUND_ID = 'LOAN'

|||

after debugging it...

When i include this Join

JOIN Statements..Fund f

ON a.FUND_ID= f.Cusip

OR

a.FUND_ID= f.Ticker

OR

a.FUND_ID= f.ClientFundId

i am getting a problem and i solved it by giving

LeftOuterJOIN Statements..Fund f

ON a.FUND_ID= f.Cusip

OR

a.FUND_ID= f.Ticker

OR

a.FUND_ID= f.ClientFundId

Thanks a lot...

Regards

Karen

Monday, March 12, 2012

Help needed on "conditional" COUNT

Hi,
I have to SELECT 2 COUNTS from a table which are conditional

i.e. one is COUNT rows where field1 = 0 and field2=0

and second is COUNT all rows

Is it possible in 1 SELECT statement to return such a resultset or what are the alternatives ?

Any input in this will sincerely be appreciated.

Thanks

If you want the values to appear in the same row, then you could use the example below.

Chris

SELECT SUM(CASE WHEN field1 = 0 AND field2 = 0 THEN 1 ELSE 0 END),

COUNT(*)

FROM MyTable

|||wow, How simple was it.

Thankyou,
I really appreciate it

Friday, March 9, 2012

Help Needed in Graph

Hi ,
I having a lengthy report which brings around 500 rows of data.. I am having a graph at the bottom of the table representing all the 500 rows of data. Since the data is large it lost its readability.
Is there any way to have a graph for each of 100 rows '?
Any help or suggestion would be helpful
Thanks in advance.
Bala
--
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.I haven't tested this, but you might try to
create the 5 different graphs using the same data set, but then filter the
dataset on each graph using rowcount function...
I'd like to know what you find if you test this...
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"SqlJunkies User" <User@.-NOSPAM-SqlJunkies.com> wrote in message
news:%23MSBaamwEHA.2804@.TK2MSFTNGP14.phx.gbl...
> Hi ,
> I having a lengthy report which brings around 500 rows of data.. I am
having a graph at the bottom of the table representing all the 500 rows of
data. Since the data is large it lost its readability.
> Is there any way to have a graph for each of 100 rows '?
> Any help or suggestion would be helpful
>
> Thanks in advance.
> Bala
> --
> Posted using Wimdows.net NntpNews Component -
> Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine
supports Post Alerts, Ratings, and Searching.

Monday, February 27, 2012

HELP ME!

Hi, locking for the answer to these questions:
1. How many rows contained in table PERSON
2. How many rows contained in teble CAR
Following table contain info about persons. Table do contain a lot of
rows!
CREATE TABLE Person
{
PersonID int NOT NULL IDENTITY(1,1)
PersNumber char(11) NOT NULL,
Name1 varchar(50) NOT NULL,
Name2 varchar(50) NOT NULL,
ShoeSize int NOT NULL,
Address varchar(50) NOT NULL,
Zip varchar(10) NOT NULL,
City varchar(50) NOT NULL
}
Further more, this table containg cars connected to persons in table
above.
CREATE TABLE Car
{
CarID int NOT NULL IDENTITY(1,1),
RegNr varchar(8) NOT NULL,
PersonID int NULL
}
Following SELECT statements are executed:
SELECT *
FROM Person P JOIN Car C ON P.PersonID = C.PersonID
(1037854 rows is affected)
SELECT PersNumber, COUNT(*)
FROM Person P JOIN Car C ON P.PersonID = C.PersonID
GROUP BY PersNumber
HAVING COUNT(*) > 1
(132892 rows are affected)
SELECT PersNumber, COUNT(*)
FROM Person P JOIN Car C ON P.PersonID = C.PersonID
GROUP BY PersNumber
HAVING COUNT(*) > 2
(0 rows are affected)
SELECT COUNT(DISTINCT P. PersonID), COUNT (DISTINCT C.CarID)
FROM Person P FULL OUTER JOIN Car C ON P.PersonID = C.PersonID
WHERE C.CarID IS NULL OR P.PersonID IS NULL
-- --
198898 114388
(1 rows are affected)
Now...the answers to this!
1. How many rows contained in table PERSON
2. How many rows contained in teble CAR
Thanks to all gurus taking time solving this. Please, if you know this
- try to explain your solution!
Thanks again!!
/Markselect count(*) from Car
go
select count(*) from person
--
current location: alicante (es)
"zekevarg" wrote:

> Hi, locking for the answer to these questions:
> 1. How many rows contained in table PERSON
> 2. How many rows contained in teble CAR
> Following table contain info about persons. Table do contain a lot of
> rows!
> CREATE TABLE Person
> {
> PersonID int NOT NULL IDENTITY(1,1)
> PersNumber char(11) NOT NULL,
> Name1 varchar(50) NOT NULL,
> Name2 varchar(50) NOT NULL,
> ShoeSize int NOT NULL,
> Address varchar(50) NOT NULL,
> Zip varchar(10) NOT NULL,
> City varchar(50) NOT NULL
> }
> Further more, this table containg cars connected to persons in table
> above.
> CREATE TABLE Car
> {
> CarID int NOT NULL IDENTITY(1,1),
> RegNr varchar(8) NOT NULL,
> PersonID int NULL
> }
> Following SELECT statements are executed:
> SELECT *
> FROM Person P JOIN Car C ON P.PersonID = C.PersonID
> (1037854 rows is affected)
> SELECT PersNumber, COUNT(*)
> FROM Person P JOIN Car C ON P.PersonID = C.PersonID
> GROUP BY PersNumber
> HAVING COUNT(*) > 1
> (132892 rows are affected)
> SELECT PersNumber, COUNT(*)
> FROM Person P JOIN Car C ON P.PersonID = C.PersonID
> GROUP BY PersNumber
> HAVING COUNT(*) > 2
> (0 rows are affected)
> SELECT COUNT(DISTINCT P. PersonID), COUNT (DISTINCT C.CarID)
> FROM Person P FULL OUTER JOIN Car C ON P.PersonID = C.PersonID
> WHERE C.CarID IS NULL OR P.PersonID IS NULL
> -- --
> 198898 114388
> (1 rows are affected)
>
> Now...the answers to this!
> 1. How many rows contained in table PERSON
> 2. How many rows contained in teble CAR
>
> Thanks to all gurus taking time solving this. Please, if you know this
> - try to explain your solution!
> Thanks again!!
> /Mark
>|||Ok, that answer would have been a bright one only when having
connection to stated tables. In my case i dont. It should be able to
answer only with information above.
Thats the tricky part!
Thanks anyway! :)|||If you want to impress you teacher, tell him/her that answers cannot be
given from the information provided. There are no constraints on these
tables so no assumptions can be made about cardinality. I believe that
primary key, foreign key and unique constraints would all be needed in order
to answer the questions based on query results.
Hope this helps.
Dan Guzman
SQL Server MVP
"zekevarg" <markussteen@.chello.se> wrote in message
news:1142331724.403236.70490@.j52g2000cwj.googlegroups.com...
> Hi, locking for the answer to these questions:
> 1. How many rows contained in table PERSON
> 2. How many rows contained in teble CAR
> Following table contain info about persons. Table do contain a lot of
> rows!
> CREATE TABLE Person
> {
> PersonID int NOT NULL IDENTITY(1,1)
> PersNumber char(11) NOT NULL,
> Name1 varchar(50) NOT NULL,
> Name2 varchar(50) NOT NULL,
> ShoeSize int NOT NULL,
> Address varchar(50) NOT NULL,
> Zip varchar(10) NOT NULL,
> City varchar(50) NOT NULL
> }
> Further more, this table containg cars connected to persons in table
> above.
> CREATE TABLE Car
> {
> CarID int NOT NULL IDENTITY(1,1),
> RegNr varchar(8) NOT NULL,
> PersonID int NULL
> }
> Following SELECT statements are executed:
> SELECT *
> FROM Person P JOIN Car C ON P.PersonID = C.PersonID
> (1037854 rows is affected)
> SELECT PersNumber, COUNT(*)
> FROM Person P JOIN Car C ON P.PersonID = C.PersonID
> GROUP BY PersNumber
> HAVING COUNT(*) > 1
> (132892 rows are affected)
> SELECT PersNumber, COUNT(*)
> FROM Person P JOIN Car C ON P.PersonID = C.PersonID
> GROUP BY PersNumber
> HAVING COUNT(*) > 2
> (0 rows are affected)
> SELECT COUNT(DISTINCT P. PersonID), COUNT (DISTINCT C.CarID)
> FROM Person P FULL OUTER JOIN Car C ON P.PersonID = C.PersonID
> WHERE C.CarID IS NULL OR P.PersonID IS NULL
> -- --
> 198898 114388
> (1 rows are affected)
>
> Now...the answers to this!
> 1. How many rows contained in table PERSON
> 2. How many rows contained in teble CAR
>
> Thanks to all gurus taking time solving this. Please, if you know this
> - try to explain your solution!
> Thanks again!!
> /Mark
>|||Actually, we should have more than enough information here to determine how
many rows are in each table. Table persons has an implied unique
constraint, and we don't need to know the constraints on table car in order
to answer the question.
The data tells us how many:
Cars are owned by a person
Persons have more than one car
Persons have more than two cars
Cars are not owned by a person
Persons do not own a car
All you need to do is add or subtract those values in order to arrive at the
answer.
Not that I am going to outright give the answer, there is somethign to be
said for actually doing your own homework.
This should be enough help to get you in the right direction.
"Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
news:uBfCkv2RGHA.4608@.tk2msftngp13.phx.gbl...
> If you want to impress you teacher, tell him/her that answers cannot be
> given from the information provided. There are no constraints on these
> tables so no assumptions can be made about cardinality. I believe that
> primary key, foreign key and unique constraints would all be needed in
order
> to answer the questions based on query results.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "zekevarg" <markussteen@.chello.se> wrote in message
> news:1142331724.403236.70490@.j52g2000cwj.googlegroups.com...
>|||Wrong, sorry. It's possible to answer only with given info.
Use affected rows as hint.|||Jim Underwood wrote:

> Actually, we should have more than enough information here to determine ho
w
> many rows are in each table. Table persons has an implied unique
> constraint, and we don't need to know the constraints on table car in orde
r
> to answer the question.
There are no constraints. The tables have IDENTITY columns but that
doesn't mean they have keys. Dan is right. On the information given
there is no way to be sure how many rows in each table.
In particular if PersonID isn't unique then the first two queries may
contain duplicates and so we can't be sure of the number of rows in the
base tables. The FULL JOIN query on the other hand only tells us the
number of distinct values, not the number of rows.
An good example of why keys are important.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||PersonID is an IDENTITY field, therefore it is unique.
I agree that identity does not qualify as a constraint/PK by general DBMS
terms, however we know that in SQL Server IDENTITY is always unique. This
is why I referred to it a an IMPLIED unique constraint.
The example is an academic one, a test of logic and DBMS knowledge, not an
ansi standards test.
If the PersonID was not an IDENTITY field then you would be correct, but by
definition IDENTITY is unique, no matter how much you or I may disapprove of
its use here. I would much prefer to see unique constraints explicitly
defined, but that does not change the fact that one has been implicitly
created by SQL Server, even if it is proprietary.
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1142349407.116675.165460@.v46g2000cwv.googlegroups.com...
> Jim Underwood wrote:
>
how
order
> There are no constraints. The tables have IDENTITY columns but that
> doesn't mean they have keys. Dan is right. On the information given
> there is no way to be sure how many rows in each table.
> In particular if PersonID isn't unique then the first two queries may
> contain duplicates and so we can't be sure of the number of rows in the
> base tables. The FULL JOIN query on the other hand only tells us the
> number of distinct values, not the number of rows.
> An good example of why keys are important.
> --
> David Portas, SQL Server MVP
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>|||Jim Underwood wrote:
> PersonID is an IDENTITY field, therefore it is unique.
> I agree that identity does not qualify as a constraint/PK by general DBMS
> terms, however we know that in SQL Server IDENTITY is always unique. This
> is why I referred to it a an IMPLIED unique constraint.
Rubbish!
CREATE TABLE T1 (x INT IDENTITY);
SET IDENTITY_INSERT T1 ON;
INSERT INTO T1 (x) VALUES (1);
INSERT INTO T1 (x) VALUES (1);
SET IDENTITY_INSERT T1 ON;
GO
CREATE TABLE T2 (x INT IDENTITY);
INSERT INTO T2 DEFAULT VALUES;
DBCC CHECKIDENT (T2,RESEED,0);
INSERT INTO T2 DEFAULT VALUES;
GO
SELECT x FROM T1;
SELECT x FROM T2;
Result:
x
--
1
1
(2 row(s) affected)
x
--
1
1
(2 row(s) affected)
As for testing DBMS knowledge, I'll bet that plenty of people reading
this can testify to experience of non-unique IDENTITY columns.
Certainly I have known of real examples.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||My humble apologies.
I have indeed shown my ignorance in this regard.
Thank you for setting me straight.
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1142351997.595277.210040@.p10g2000cwp.googlegroups.com...
> Jim Underwood wrote:
DBMS
This
> Rubbish!
> CREATE TABLE T1 (x INT IDENTITY);
> SET IDENTITY_INSERT T1 ON;
> INSERT INTO T1 (x) VALUES (1);
> INSERT INTO T1 (x) VALUES (1);
> SET IDENTITY_INSERT T1 ON;
> GO
> CREATE TABLE T2 (x INT IDENTITY);
> INSERT INTO T2 DEFAULT VALUES;
> DBCC CHECKIDENT (T2,RESEED,0);
> INSERT INTO T2 DEFAULT VALUES;
> GO
> SELECT x FROM T1;
> SELECT x FROM T2;
> Result:
> x
> --
> 1
> 1
> (2 row(s) affected)
> x
> --
> 1
> 1
> (2 row(s) affected)
> As for testing DBMS knowledge, I'll bet that plenty of people reading
> this can testify to experience of non-unique IDENTITY columns.
> Certainly I have known of real examples.
> --
> David Portas, SQL Server MVP
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>

HELP ME!

Hi, locking for the answer to these questions:
1. How many rows contained in table PERSON
2. How many rows contained in teble CAR
Following table contain info about persons. Table do contain a lot of
rows!
CREATE TABLE Person
{
PersonID int NOT NULL IDENTITY(1,1)
PersNumber char(11) NOT NULL,
Name1 varchar(50) NOT NULL,
Name2 varchar(50) NOT NULL,
ShoeSize int NOT NULL,
Address varchar(50) NOT NULL,
Zip varchar(10) NOT NULL,
City varchar(50) NOT NULL
}
Further more, this table containg cars connected to persons in table
above.
CREATE TABLE Car
{
CarID int NOT NULL IDENTITY(1,1),
RegNr varchar(8) NOT NULL,
PersonID int NULL
}
Following SELECT statements are executed:
SELECT *
FROM Person P JOIN Car C ON P.PersonID = C.PersonID
(1037854 rows is affected)
SELECT PersNumber, COUNT(*)
FROM Person P JOIN Car C ON P.PersonID = C.PersonID
GROUP BY PersNumber
HAVING COUNT(*) > 1
(132892 rows are affected)
SELECT PersNumber, COUNT(*)
FROM Person P JOIN Car C ON P.PersonID = C.PersonID
GROUP BY PersNumber
HAVING COUNT(*) > 2
(0 rows are affected)
SELECT COUNT(DISTINCT P. PersonID), COUNT (DISTINCT C.CarID)
FROM Person P FULL OUTER JOIN Car C ON P.PersonID = C.PersonID
WHERE C.CarID IS NULL OR P.PersonID IS NULL
-- --
198898 114388
(1 rows are affected)
Now...the answers to this!
1. How many rows contained in table PERSON
2. How many rows contained in teble CAR
Thanks to all gurus taking time solving this. Please, if you know this
- try to explain your solution!
Thanks again!!
/MarkHELP ME... so lame... come on use a better subject line and you will get
more feedbacks.
"zekevarg" <markussteen@.chello.se> wrote in message
news:1142331597.178743.86510@.u72g2000cwu.googlegroups.com...
> Hi, locking for the answer to these questions:
> 1. How many rows contained in table PERSON
> 2. How many rows contained in teble CAR
> Following table contain info about persons. Table do contain a lot of
> rows!
> CREATE TABLE Person
> {
> PersonID int NOT NULL IDENTITY(1,1)
> PersNumber char(11) NOT NULL,
> Name1 varchar(50) NOT NULL,
> Name2 varchar(50) NOT NULL,
> ShoeSize int NOT NULL,
> Address varchar(50) NOT NULL,
> Zip varchar(10) NOT NULL,
> City varchar(50) NOT NULL
> }
> Further more, this table containg cars connected to persons in table
> above.
> CREATE TABLE Car
> {
> CarID int NOT NULL IDENTITY(1,1),
> RegNr varchar(8) NOT NULL,
> PersonID int NULL
> }
> Following SELECT statements are executed:
> SELECT *
> FROM Person P JOIN Car C ON P.PersonID = C.PersonID
> (1037854 rows is affected)
> SELECT PersNumber, COUNT(*)
> FROM Person P JOIN Car C ON P.PersonID = C.PersonID
> GROUP BY PersNumber
> HAVING COUNT(*) > 1
> (132892 rows are affected)
> SELECT PersNumber, COUNT(*)
> FROM Person P JOIN Car C ON P.PersonID = C.PersonID
> GROUP BY PersNumber
> HAVING COUNT(*) > 2
> (0 rows are affected)
> SELECT COUNT(DISTINCT P. PersonID), COUNT (DISTINCT C.CarID)
> FROM Person P FULL OUTER JOIN Car C ON P.PersonID = C.PersonID
> WHERE C.CarID IS NULL OR P.PersonID IS NULL
> -- --
> 198898 114388
> (1 rows are affected)
>
> Now...the answers to this!
> 1. How many rows contained in table PERSON
> 2. How many rows contained in teble CAR
>
> Thanks to all gurus taking time solving this. Please, if you know this
> - try to explain your solution!
> Thanks again!!
> /Mark
>|||interesting answer.. :)