Showing posts with label generate. Show all posts
Showing posts with label generate. Show all posts

Friday, March 9, 2012

Need a tip to generate Identity

Hi all,
I need the same functionality as IDENTITY(int,1,1) but only in a SELECT
(without the INTO table part)
I want to do something like this:
select IDENTITY(int,1,1) as ident, * from my_table
How to do that?
I use MS-SQL2000.
Lilian.This is a multi-part message in MIME format.
--=_NextPart_000_0AC4_01C381C4.ABEE7350
Content-Type: text/plain;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
Try:
select
(select count(*) from MyTable as i
where i.PK <=3D o.PK) as ident
, o.*
from
MyTable as o
-- Tom
---
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"Lilian Pigallio" <lpigallio@.nospam.com> wrote in message =news:#TlBUTegDHA.1872@.TK2MSFTNGP09.phx.gbl...
Hi all,
I need the same functionality as IDENTITY(int,1,1) but only in a SELECT
(without the INTO table part)
I want to do something like this:
select IDENTITY(int,1,1) as ident, * from my_table
How to do that?
I use MS-SQL2000.
Lilian.
--=_NextPart_000_0AC4_01C381C4.ABEE7350
Content-Type: text/html;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

Try:
select
(select =count(*) from MyTable as i
= where i.PK <=3D o.PK) as ident
, =o.*
from
MyTable as o
-- Tom
---T=homas A. Moreau, BSc, PhD, MCSE, MCDBASQL Server MVPColumnist, SQL =Server ProfessionalToronto, ON Canadahttp://www.pinnaclepublishing.com/sql">www.pinnaclepublishing.com=/sql
"Lilian Pigallio" wrote =in message news:#TlBUTegDHA.1872=@.TK2MSFTNGP09.phx.gbl...Hi all,I need the same functionality as IDENTITY(int,1,1) but only =in a SELECT(without the INTO table part)I want to do something =like this: select =IDENTITY(int,1,1) as ident, * from my_tableHow to do that?I use MS-SQL2000.Lilian.

--=_NextPart_000_0AC4_01C381C4.ABEE7350--|||this is a workable solution, but why don't you want to use
SELECT INTO with identity function? because solution
suggested by Tom will be very slow if the resultset is
really large. In that case SELECT INTO result table and
then getting selecting from result table will run faster.
>--Original Message--
>Try:
>select
> (select count(*) from MyTable as i
> where i.PK <= o.PK) as ident
>, o.*
>from
> MyTable as o
>--
>Tom
>----
--
>Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
>SQL Server MVP
>Columnist, SQL Server Professional
>Toronto, ON Canada
>www.pinnaclepublishing.com/sql
>
>"Lilian Pigallio" <lpigallio@.nospam.com> wrote in message
news:#TlBUTegDHA.1872@.TK2MSFTNGP09.phx.gbl...
>Hi all,
>I need the same functionality as IDENTITY(int,1,1) but
only in a SELECT
>(without the INTO table part)
>I want to do something like this:
> select IDENTITY(int,1,1) as ident, * from my_table
>
>How to do that?
>I use MS-SQL2000.
>Lilian.
>|||This is a multi-part message in MIME format.
--=_NextPart_000_0015_01C3827D.24033A20
Content-Type: text/plain;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
Thanks :^)
"Tom Moreau" <tom@.dont.spam.me.cips.ca> wrote in message =news:%23NGj2YegDHA.2072@.TK2MSFTNGP10.phx.gbl...
Try:
select
(select count(*) from MyTable as i
where i.PK <=3D o.PK) as ident
, o.*
from
MyTable as o
-- Tom
---
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"Lilian Pigallio" <lpigallio@.nospam.com> wrote in message =news:#TlBUTegDHA.1872@.TK2MSFTNGP09.phx.gbl...
Hi all,
I need the same functionality as IDENTITY(int,1,1) but only in a =SELECT
(without the INTO table part)
I want to do something like this:
select IDENTITY(int,1,1) as ident, * from my_table
How to do that?
I use MS-SQL2000.
Lilian.
--=_NextPart_000_0015_01C3827D.24033A20
Content-Type: text/html;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

Thanks :^)
"Tom Moreau" = wrote in message news:%23NGj2YegDHA.=2072@.TK2MSFTNGP10.phx.gbl...
Try:

select
(select =count(*) from MyTable as i
= where i.PK <=3D o.PK) as ident
, =o.*
from
MyTable as = o
-- Tom

=---T=homas A. Moreau, BSc, PhD, MCSE, MCDBASQL Server MVPColumnist, SQL =Server ProfessionalToronto, ON Canadahttp://www.pinnaclepublishing.com/sql">www.pinnaclepublishing.com=/sql


"Lilian Pigallio" =wrote in message news:#TlBUTegDHA.1872=@.TK2MSFTNGP09.phx.gbl...Hi all,I need the same functionality as IDENTITY(int,1,1) but =only in a SELECT(without the INTO table part)I want to do something =like this: select =IDENTITY(int,1,1) as ident, * from my_tableHow to do that?I use MS-SQL2000.Lilian.

--=_NextPart_000_0015_01C3827D.24033A20--

Wednesday, March 7, 2012

Need a Sql Scriptor

I need to generate the Sql Scripts for a particular Database in a Sql Server 7.0.

Also i need help in the Data Migration of Foxpro2.6a to SqlServer.

If there are any good tools for such conversion,I am very much thankful to all who comes with a good reply.

Thanks & Regds,
B.SethuJust right click any of your databases and choose "all tasks" then "generate sql scripts". If you have an odbc driver for the foxpro database then you can use the dts import wizard. If not, just export the foxpro database to a delimited file and use the wizard.|||To migrate your data look into Distributed Transaction Coordinator (DTS),which comes with SQL Server. Also use Google (http://www.google.com) to research on the migration.|||Thanks for the reply.I need to create Insert Statements for all my Master Tables(say 1000).I need a tool which gives me the insert statements,either if i give the Database or Tables of the Database.

Also for foxpro we don't have any ODBC driver,moreover my all foxpro tables have memo fields,which i can't transform via DTS.

Thanks & Regds,
B.Sethu|||To generate the scripts for all of your databases you can use the sql-dmo script method - look at your books online.

What happens when you try to transform the foxpro table with a memo field ?|||I've created a stored procedure that will generate the INSERT statements

Example in Pubs database
exec usp_CreateInsert authors

INSERT authors ( au_id, au_lname, au_fname, phone, address, city, state, zip, contract)
VALUES ('409-56-7008','Bennet','Abraham','415 658-9932','6223 Bateman St.','Berkeley','CA','94705',1)
INSERT authors ( au_id, au_lname, au_fname, phone, address, city, state, zip, contract)
VALUES ('427-17-2319','Dull','Ann','415 836-7128','3410 Blonde St.','Palo Alto','CA','94301',1)

I've attached the script|||For the foxpro conversion - have you tried converting to access first then to sql server ?

need a query to join 3 tables

hi everyone - wondering if anyone can help me in this: i have got 3 tables i.e
1.Invoice
2.Customer
3.Agents
and i want to generate an invoice using the info from these two tables how can i do that. the scenario is that for one invoice there can be multiple entries

invID,CustID,AgentID,productPrice |
1 1 1 40 |
1 2 2 50 | this is the data for 1 invoice
1 3 3 70 |
i want a join query so that i can get the names of the customers and agents on behalf of their ids in the invoice table and all the info from invoice table so that it can show the result like this

invID,CustName,AgentName,productPrice |
1 xyz a 40 |
1 yyy b 50 | this is the data for 1 invoice
1 zzz c 70 |

================================================== =======select invID
, CustName
, AgentName
, productPrice
from Invoice
inner
join Customer
on Invoice.CustID
= Customer.CustID
inner
join Agents
on Invoice.AgentID
= Agents.AgentID|||thank you thats what i wanted

Need a kick in the right direction w/this query

Here is a link to the DDL since it would take up a lot of room here.
http://damageinc.org/DDL.html
After you use that to generate the table and some sample data, here is the
problem I need help with.
You will see the following data, if you use this query...
SELECT DISTINCT Apps.AppName, TestCases.TestCase , Tests.Attributes,
Reports.Result, Reports.ReportDate
FROM
Reports
LEFT OUTER JOIN TestCases ON TestCases.TestCaseID = Reports.TestID
LEFT OUTER JOIN Tests ON TestCases.TestCaseID = Tests.TestID
LEFT OUTER JOIN Apps ON TestCases.AppID = Apps.AppID
AppName TestCase Attribute
Result ReportDate
Test App 1 Run for 30 minutes Attribute 1 Fail
2006-06-25 19:58:31.800
Test App 1 Run for 30 minutes Attribute 1 Pass
2006-06-25 19:58:29.800
Test App 1 Run for 30 minutes Attribute 1 Pass
2006-06-25 19:58:30.800
Test App 1 Run for 45 minutes Attribute 2 Fail
2006-06-25 19:58:33.800
Test App 1 Run for 45 minutes Attribute 2 Fail
2006-06-25 19:58:34.800
Test App 1 Run for 45 minutes Attribute 2 Pass
2006-06-25 19:58:32.800
Test App 1 Run for 60 minutes Attribute 3 Fail
2006-06-25 19:58:36.863
Test App 1 Run for 60 minutes Attribute 3 Pass
2006-06-25 19:58:35.863
Test App 1 Run for 60 minutes Attribute 3 Pass
2006-06-25 19:58:37.863
What I need to get is the count most recent result per TestCase regardless
of attribute.
So I was trying to do it visually by using this query..
SELECT tc.TestCase, tc.mostRecent, tc.Result
FROM Reports rp
RIGHT JOIN
(
SELECT TestCases.TestCase ,Reports.Result, MAX ( Reports.ReportDate ) AS
mostRecent
FROM Reports
LEFT OUTER JOIN TestCases ON TestCases.TestCaseID = Reports.TestID
LEFT OUTER JOIN Tests ON TestCases.TestCaseID = Tests.TestID
WHERE ( (Tests.Attributes = 'Attribute 1') OR (Tests.Attributes =
'Attribute 2') OR (Tests.Attributes = 'Attribute 3') )
GROUP BY TestCases.TestCase, Result) tc ON (tc.mostRecent =
rp.ReportDate ) ORDER BY TestCAse
Which will give you this data...
TestCase mostRecent Result
Run for 30 minutes 2006-06-25 19:58:31.800 Fail
Run for 30 minutes 2006-06-25 19:58:30.800 Pass
Run for 45 minutes 2006-06-25 19:58:34.800 Fail
Run for 45 minutes 2006-06-25 19:58:32.800 Pass
Run for 60 minutes 2006-06-25 19:58:36.863 Fail
Run for 60 minutes 2006-06-25 19:58:37.863 Pass
Which as you can tell is giving me both the most recent pass & fail result,
where I want the most recent result regardless of Pass/Fail.
Which in turn, makes my count query wrong as well...
SELECT COUNT(DISTINCT tc.TestCase) As Count,
COUNT(DISTINCT CASE rp.Result WHEN 'Pass' THEN rp.ReportID ELSE NULL END) as
Pass,
COUNT(DISTINCT CASE rp.Result WHEN 'Fail' THEN rp.ReportID ELSE NULL END) as
Fail
FROM Reports rp
RIGHT JOIN
(
SELECT TestCases.TestCase ,Reports.Result, MAX ( Reports.ReportDate ) AS
mostRecent
FROM Reports
LEFT OUTER JOIN TestCases ON TestCases.TestCaseID = Reports.TestID
LEFT OUTER JOIN Tests ON TestCases.TestCaseID = Tests.TestID
WHERE ( (Tests.Attributes = 'Attribute 1') OR (Tests.Attributes =
'Attribute 2') OR (Tests.Attributes = 'Attribute 3') )
GROUP BY TestCases.TestCase, Result) tc ON (tc.mostRecent = rp.ReportDate )
Which will give me
Count Pass Fail
3 3 3
Instead of the result I am looking for of..
Count Pass Fail
3 1 2Select Count(*) As 'Count',
Sum(Case When Result = 'Pass' Then 1 Else 0 End) As 'Pass',
Sum(Case When Result = 'Fail' Then 1 Else 0 End) As 'Fail'
From Reports r
Where r.ReportDate In
(Select Max(r.ReportDate)
From Reports r
Inner Join TestCases tc On r.TestID = tc.TestCaseID
Inner Join Tests t On tc.TestCaseID = t.TestID
Inner Join Apps a On tc.AppID = a.AppID
Where t.Attributes In ('Attribute 1', 'Attribute 2', 'Attribute 3')
Group By a.AppName, tc.TestCase)
The above query assumes that there are no duplicates in Reports.ReportDate.
I changed your Left Outer Joins to Inner Joins since if for a Report row,
you don't have a TestCases row and a Tests row, then the Attributes column
will nave NULL in it, so the where condition would be false. So your Left
Outer Join gives the same result as an Inner Join, but Inner Joins are ofter
faster.
BTW, your DDL is not too long to post to this group (IMHO) and you will have
better luck if you just include it the post rather than a web site since
some people are reluctant to go to an unknown site.
Tom
"Lucas Graf" <lgraf2000@.comcast.net> wrote in message
news:uJYRRBNmGHA.4064@.TK2MSFTNGP02.phx.gbl...
> Here is a link to the DDL since it would take up a lot of room here.
> http://damageinc.org/DDL.html
> After you use that to generate the table and some sample data, here is the
> problem I need help with.
> You will see the following data, if you use this query...
>
> SELECT DISTINCT Apps.AppName, TestCases.TestCase , Tests.Attributes,
> Reports.Result, Reports.ReportDate
> FROM
> Reports
> LEFT OUTER JOIN TestCases ON TestCases.TestCaseID = Reports.TestID
> LEFT OUTER JOIN Tests ON TestCases.TestCaseID = Tests.TestID
> LEFT OUTER JOIN Apps ON TestCases.AppID = Apps.AppID
> AppName TestCase Attribute Result
> ReportDate
> Test App 1 Run for 30 minutes Attribute 1 Fail
> 2006-06-25 19:58:31.800
> Test App 1 Run for 30 minutes Attribute 1 Pass
> 2006-06-25 19:58:29.800
> Test App 1 Run for 30 minutes Attribute 1 Pass
> 2006-06-25 19:58:30.800
> Test App 1 Run for 45 minutes Attribute 2 Fail
> 2006-06-25 19:58:33.800
> Test App 1 Run for 45 minutes Attribute 2 Fail
> 2006-06-25 19:58:34.800
> Test App 1 Run for 45 minutes Attribute 2 Pass
> 2006-06-25 19:58:32.800
> Test App 1 Run for 60 minutes Attribute 3 Fail
> 2006-06-25 19:58:36.863
> Test App 1 Run for 60 minutes Attribute 3 Pass
> 2006-06-25 19:58:35.863
> Test App 1 Run for 60 minutes Attribute 3 Pass
> 2006-06-25 19:58:37.863
>
> What I need to get is the count most recent result per TestCase regardless
> of attribute.
> So I was trying to do it visually by using this query..
> SELECT tc.TestCase, tc.mostRecent, tc.Result
> FROM Reports rp
> RIGHT JOIN
> (
> SELECT TestCases.TestCase ,Reports.Result, MAX ( Reports.ReportDate ) AS
> mostRecent
> FROM Reports
> LEFT OUTER JOIN TestCases ON TestCases.TestCaseID = Reports.TestID
> LEFT OUTER JOIN Tests ON TestCases.TestCaseID = Tests.TestID
> WHERE ( (Tests.Attributes = 'Attribute 1') OR (Tests.Attributes =
> 'Attribute 2') OR (Tests.Attributes = 'Attribute 3') )
> GROUP BY TestCases.TestCase, Result) tc ON (tc.mostRecent =
> rp.ReportDate ) ORDER BY TestCAse
>
> Which will give you this data...
> TestCase mostRecent Result
> Run for 30 minutes 2006-06-25 19:58:31.800 Fail
> Run for 30 minutes 2006-06-25 19:58:30.800 Pass
> Run for 45 minutes 2006-06-25 19:58:34.800 Fail
> Run for 45 minutes 2006-06-25 19:58:32.800 Pass
> Run for 60 minutes 2006-06-25 19:58:36.863 Fail
> Run for 60 minutes 2006-06-25 19:58:37.863 Pass
> Which as you can tell is giving me both the most recent pass & fail
> result, where I want the most recent result regardless of Pass/Fail.
> Which in turn, makes my count query wrong as well...
> SELECT COUNT(DISTINCT tc.TestCase) As Count,
> COUNT(DISTINCT CASE rp.Result WHEN 'Pass' THEN rp.ReportID ELSE NULL END)
> as Pass,
> COUNT(DISTINCT CASE rp.Result WHEN 'Fail' THEN rp.ReportID ELSE NULL END)
> as Fail
> FROM Reports rp
> RIGHT JOIN
> (
> SELECT TestCases.TestCase ,Reports.Result, MAX ( Reports.ReportDate ) AS
> mostRecent
> FROM Reports
> LEFT OUTER JOIN TestCases ON TestCases.TestCaseID = Reports.TestID
> LEFT OUTER JOIN Tests ON TestCases.TestCaseID = Tests.TestID
> WHERE ( (Tests.Attributes = 'Attribute 1') OR (Tests.Attributes =
> 'Attribute 2') OR (Tests.Attributes = 'Attribute 3') )
> GROUP BY TestCases.TestCase, Result) tc ON (tc.mostRecent =
> rp.ReportDate )
> Which will give me
>
> Count Pass Fail
> 3 3 3
>
> Instead of the result I am looking for of..
> Count Pass Fail
> 3 1 2
>
>|||Lucas
Thanks fro posting DDL
See if this helps you
SELECT TestCase,COUNT(CASE WHEN Result='Fail' THEN ReportDate END) AS
'Fail',
COUNT(CASE WHEN Result='Pass' THEN ReportDate END) AS 'Pass'
FROM
(
SELECT Apps.AppName, TestCases.TestCase , Tests.Attributes,
Reports.Result, Reports.ReportDate
FROM
Reports
LEFT OUTER JOIN TestCases ON TestCases.TestCaseID = Reports.TestID
LEFT OUTER JOIN Tests ON TestCases.TestCaseID = Tests.TestID
LEFT OUTER JOIN Apps ON TestCases.AppID = Apps.AppID
) AS Der GROUP BY TestCase
"Lucas Graf" <lgraf2000@.comcast.net> wrote in message
news:uJYRRBNmGHA.4064@.TK2MSFTNGP02.phx.gbl...
> Here is a link to the DDL since it would take up a lot of room here.
> http://damageinc.org/DDL.html
> After you use that to generate the table and some sample data, here is the
> problem I need help with.
> You will see the following data, if you use this query...
>
> SELECT DISTINCT Apps.AppName, TestCases.TestCase , Tests.Attributes,
> Reports.Result, Reports.ReportDate
> FROM
> Reports
> LEFT OUTER JOIN TestCases ON TestCases.TestCaseID = Reports.TestID
> LEFT OUTER JOIN Tests ON TestCases.TestCaseID = Tests.TestID
> LEFT OUTER JOIN Apps ON TestCases.AppID = Apps.AppID
> AppName TestCase Attribute Result
> ReportDate
> Test App 1 Run for 30 minutes Attribute 1 Fail
> 2006-06-25 19:58:31.800
> Test App 1 Run for 30 minutes Attribute 1 Pass
> 2006-06-25 19:58:29.800
> Test App 1 Run for 30 minutes Attribute 1 Pass
> 2006-06-25 19:58:30.800
> Test App 1 Run for 45 minutes Attribute 2 Fail
> 2006-06-25 19:58:33.800
> Test App 1 Run for 45 minutes Attribute 2 Fail
> 2006-06-25 19:58:34.800
> Test App 1 Run for 45 minutes Attribute 2 Pass
> 2006-06-25 19:58:32.800
> Test App 1 Run for 60 minutes Attribute 3 Fail
> 2006-06-25 19:58:36.863
> Test App 1 Run for 60 minutes Attribute 3 Pass
> 2006-06-25 19:58:35.863
> Test App 1 Run for 60 minutes Attribute 3 Pass
> 2006-06-25 19:58:37.863
>
> What I need to get is the count most recent result per TestCase regardless
> of attribute.
> So I was trying to do it visually by using this query..
> SELECT tc.TestCase, tc.mostRecent, tc.Result
> FROM Reports rp
> RIGHT JOIN
> (
> SELECT TestCases.TestCase ,Reports.Result, MAX ( Reports.ReportDate ) AS
> mostRecent
> FROM Reports
> LEFT OUTER JOIN TestCases ON TestCases.TestCaseID = Reports.TestID
> LEFT OUTER JOIN Tests ON TestCases.TestCaseID = Tests.TestID
> WHERE ( (Tests.Attributes = 'Attribute 1') OR (Tests.Attributes =
> 'Attribute 2') OR (Tests.Attributes = 'Attribute 3') )
> GROUP BY TestCases.TestCase, Result) tc ON (tc.mostRecent =
> rp.ReportDate ) ORDER BY TestCAse
>
> Which will give you this data...
> TestCase mostRecent Result
> Run for 30 minutes 2006-06-25 19:58:31.800 Fail
> Run for 30 minutes 2006-06-25 19:58:30.800 Pass
> Run for 45 minutes 2006-06-25 19:58:34.800 Fail
> Run for 45 minutes 2006-06-25 19:58:32.800 Pass
> Run for 60 minutes 2006-06-25 19:58:36.863 Fail
> Run for 60 minutes 2006-06-25 19:58:37.863 Pass
> Which as you can tell is giving me both the most recent pass & fail
> result, where I want the most recent result regardless of Pass/Fail.
> Which in turn, makes my count query wrong as well...
> SELECT COUNT(DISTINCT tc.TestCase) As Count,
> COUNT(DISTINCT CASE rp.Result WHEN 'Pass' THEN rp.ReportID ELSE NULL END)
> as Pass,
> COUNT(DISTINCT CASE rp.Result WHEN 'Fail' THEN rp.ReportID ELSE NULL END)
> as Fail
> FROM Reports rp
> RIGHT JOIN
> (
> SELECT TestCases.TestCase ,Reports.Result, MAX ( Reports.ReportDate ) AS
> mostRecent
> FROM Reports
> LEFT OUTER JOIN TestCases ON TestCases.TestCaseID = Reports.TestID
> LEFT OUTER JOIN Tests ON TestCases.TestCaseID = Tests.TestID
> WHERE ( (Tests.Attributes = 'Attribute 1') OR (Tests.Attributes =
> 'Attribute 2') OR (Tests.Attributes = 'Attribute 3') )
> GROUP BY TestCases.TestCase, Result) tc ON (tc.mostRecent =
> rp.ReportDate )
> Which will give me
>
> Count Pass Fail
> 3 3 3
>
> Instead of the result I am looking for of..
> Count Pass Fail
> 3 1 2
>
>|||Hi guys, thanks for the help so far.
I am really close now. One remaining problem, say there is no report s for
say testcase 3 (delete any reports w/the TestID of 3 in it).
Running the query will give me
Count Pass Fail
2 0 2
What i need is to show the total test cases even if there is no result(s)
for some, and the count of the ones where there are results for like so..
Count Pass Fail
3 0 2|||Select Count(*)
+ (Select Count(*) From
TestCases tc
Where Not Exists (Select 1 From Reports r Where r.TestID =
tc.TestCaseID)) As 'Count',
Sum(Case When Result = 'Pass' Then 1 Else 0 End) As 'Pass',
Sum(Case When Result = 'Fail' Then 1 Else 0 End) As 'Fail'
From Reports r
Where r.ReportDate In
(Select Max(r.ReportDate)
From Reports r
Inner Join TestCases tc On r.TestID = tc.TestCaseID
Inner Join Tests t On tc.TestCaseID = t.TestID
Inner Join Apps a On tc.AppID = a.AppID
Where t.Attributes In ('Attribute 1', 'Attribute 2', 'Attribute 3')
Group By a.AppName, tc.TestCase)
Tom
"Lucas Graf" <lgraf2000@.comcast.net> wrote in message
news:uEX$yZVmGHA.492@.TK2MSFTNGP05.phx.gbl...
> Hi guys, thanks for the help so far.
> I am really close now. One remaining problem, say there is no report s
> for say testcase 3 (delete any reports w/the TestID of 3 in it).
> Running the query will give me
> Count Pass Fail
> 2 0 2
>
> What i need is to show the total test cases even if there is no result(s)
> for some, and the count of the ones where there are results for like so..
> Count Pass Fail
> 3 0 2
>
>|||Thanks Tom "the master" Cooper!
I appreciate everyone's help as well, every time I post a question I get
another nugget of i nformation to store away.
"Tom Cooper" <tom.no.spam.please.cooper@.comcast.net> wrote in message
news:wvKdnRf8W_cuoT3ZnZ2dnUVZ_oKdnZ2d@.co
mcast.com...
> Select Count(*)
> + (Select Count(*) From
> TestCases tc
> Where Not Exists (Select 1 From Reports r Where r.TestID =
> tc.TestCaseID)) As 'Count',
> Sum(Case When Result = 'Pass' Then 1 Else 0 End) As 'Pass',
> Sum(Case When Result = 'Fail' Then 1 Else 0 End) As 'Fail'
> From Reports r
> Where r.ReportDate In
> (Select Max(r.ReportDate)
> From Reports r
> Inner Join TestCases tc On r.TestID = tc.TestCaseID
> Inner Join Tests t On tc.TestCaseID = t.TestID
> Inner Join Apps a On tc.AppID = a.AppID
> Where t.Attributes In ('Attribute 1', 'Attribute 2', 'Attribute 3')
> Group By a.AppName, tc.TestCase)
> Tom
> "Lucas Graf" <lgraf2000@.comcast.net> wrote in message
> news:uEX$yZVmGHA.492@.TK2MSFTNGP05.phx.gbl...
>|||Tom, maybe I could pick your brain one more time :)
For whatever reason on my actual tables I still can't get what I need :(
I have updated the DDL with the actual tables and a sample of table data of
what I am actually using.
http://damageinc.org/DDL.html (The DDL is too large to post, the message
gets kicked back to me)
AFter you enter that DDL
If you run the query..
SELECT Apps.AppName, Tests.TestCase, TestCases.Type
FROM
TestCases
LEFT OUTER JOIN Apps ON TestCases.AppID = Apps.ID
LEFT OUTER JOIN Tests ON TestCases.TestID = Tests.ID
WHERE
(
(
(Proj1 = '87' OR Proj2 = '87' OR Proj3 = '87' OR Proj4 = '87' OR Proj5 =
'87')
OR
(Proj1 = '88' OR Proj2 = '88' OR Proj3 = '88' OR Proj4 = '88' OR Proj5 =
'88')
)
AND (TestCases.Card = 'G71_D' OR TestCases.Card = 'G70_D' OR TestCases.Card
= 'G72_D' OR TestCases.Card = 'G73_D')
AND TestCases.OS = 'Windows Vista'
)
GROUP BY AppName, TestCase,TestCases.Type
You will see
AppName TestCase
Type
3D Mark 2003 Benchmark: 1600x1200x32 4xAA 8x Aniso D3D Benchmarks
3D Mark 2003 Benchmark: 1600x1200x32 4xAA 8x Aniso Games
3D Mark 2003 Benchmark: Default 2x AA 4x Aniso D3D
Benchmarks
3D Mark 2003 Benchmark: Default 2x AA 4x Aniso G ames
.
.
.
.
There are 97 tests there.
What I need is that 97 for the count, then the count of the most recent
pass/fail result(s) (if there is a result) for each of those tests.
Using
Select Count(*) As 'Count',
Sum(Case When Result = 'Pass' Then 1 Else 0 End) As 'Pass',
Sum(Case When Result = 'Fail' Then 1 Else 0 End) As 'Fail'
From Reports r
Where r.ReportDate In
(Select Max(r.ReportDate)
From Reports r
Inner Join TestCases tc On r.TestCaseID = tc.ID
Inner Join Tests t On tc.TestID = t.ID
Inner Join Apps a On tc.AppID = a.ID
WHERE
(
(
(tc.Proj1 = '87' OR tc.Proj2 = '87' OR tc.Proj3 = '87' OR tc.Proj4 = '87'
OR tc.Proj5 = '87')
OR
(tc.Proj1 = '88' OR tc.Proj2 = '88' OR tc.Proj3 = '88' OR tc.Proj4 = '88'
OR tc.Proj5 = '88')
)
AND (tc.Card = 'G71_D' OR tc.Card = 'G70_D' OR tc.Card = 'G72_D' OR tc.Card
= 'G73_D')
AND tc.OS = 'Windows Vista'
)
Group By a.AppName, t.TestCase)
Gives me
Count Pass Fail
25 2 23
Which is obviously wrong, since the Count should be 97.
I have to be overthinking something here...
========================================
====================================
========