Showing posts with label requirement. Show all posts
Showing posts with label requirement. Show all posts

Friday, March 23, 2012

Looping in a query

Hello Everybody,

I have a requirement where the query needs to looped.

I have a table f553002A. In this table i have iykit,iyitm as columns.

for every iykit,there can be a set of iyitm

like this

select KIT, ITM from F553002A where KIT = 11758

KIT ITM

11758 11494

11758 11705

11758 11713

11758 11868

Again for every ITM as KIT in the same table ,there can have set of values(ITM) like this

select KIT, ITM from F553002A where KIT = 11713 (parent’s ITM)

KIT ITM

11713.0 2917.0
11713.0 2910.0
11713.0 5013.0
11713.0 2890.0
11713.0 2873.0
11713.0 2843.0
11713.0 2856.0
11713.0 2836.0
11713.0 2879.0
11713.0 7974.0
11713.0 2789.0
11713.0 2842.0
11713.0 2915.0
11713.0 2885.0
11713.0 2908.0
11713.0 2858.0
11713.0 2871.0
11713.0 2841.0

the same with 11494,11705,11868.

Again 2917.0 (ITM) in the above example as KIT can have another set of ITM's in the same table

I want all the END ITM's along with there Grand parent KIT and Immediate Parent Kit returned in a result set.

For Ex

11758 11713.0 2917.0

....

...

..

.

11758 11494 ...........................

........

...

..

.

However i know i can achieve this with Stored procdeure. I want this to be implemented in SQL Query where i can embeed it in a VBscript

Please help me in writing the query for this. Thanks in advance

We are using sql server 2000. not 2005

here you go..

Code Snippet

Create Table #f553002a (

[KIT] int ,

[ITM] int

);

Insert Into #f553002a Values(1,2);

Insert Into #f553002a Values(1,3);

Insert Into #f553002a Values(1,4);

Insert Into #f553002a Values(1,5);

Insert Into #f553002a Values(2,6);

Insert Into #f553002a Values(3,8);

Insert Into #f553002a Values(4,9);

Insert Into #f553002a Values(5,10);

Insert Into #f553002a Values(6,11);

Insert Into #f553002a Values(7,12);

Insert Into #f553002a Values(8,13);

Insert Into #f553002a Values(9,14);

Insert Into #f553002a Values(10,2);

Insert Into #f553002a Values(11,3);

;With CTE(KIT,ITM,Level)

as

(

Select KIT,ITM,1 Level from #f553002a Where KIT = 3 --@.StartKitValue

Union ALL

Select Child.KIT,Child.ITM,Main.Level + 1 From CTE Main

Join #f553002a Child On Main.Itm = Child.Kit

)

Select KIT,ITM From CTE Order By Level

|||

Can any body through a light why the query below is returning syntax error

With CTE(IYKIT,IYITM,Level)

as

(

Select IYKIT,IYITM,1 Level from f553002a Where IYKIT = 11758 --@.StartKitValue

Union ALL

Select Child.IYKIT,Child.IYITM,Main.Level + 1 From CTE Main

Join f553002a Child On Main.IYItm = Child.IYKit

)

Select IYKIT,IYITM From CTE Order By Level

Msg 156, Level 15, State 1, Line 1

Incorrect syntax near the keyword 'With'.

I am running this on sql server 2005 Management studio.

How ever in my question,i requested for a solution which can work in SQL server 2000, but this works only in sql server 2005

|||

CTE only work with SQL Server 2005. You missed the semicolon ; before the WITH.

In 2000 you can use recursive sp call... let me try this..

sql

Looping each record

Hi,

My report requirement of customer activity report.

For each customer, my report should show the summary by purchase catgory and then individual transaction details.

Customer Name: Tom Tim

Books: 100

Computers : 2

Others: 23

(then all 125 transactions should be listed).

Same summary and detail should be repeated for each customer in the same single report. (there are aound 200 customers)

How can I achieve this? (other than Sub report). Sub-report seems to be very slow in rendering?

Thanks,

Vasanth

Wouldn't a list work? The list would repeat for each customer.|||Within the list, I am not able to user another table to list the transaction because list allows only group (aggregate) functionalities.|||any ideas pls?

Loopig Each Record in dataset

Hi,
My report requirement of customer activity report.
For each customer, my report should show the summary by purchase
catgory and then individual transaction details.
Customer Name: Tom Tim
Books: 100
Computers : 2
Others: 23
(then all 125 transactions should be listed).
Same summary and detail should be repeated for each customer in the
same single report. (there are aound 200 customers)
How can I achieve this? (other than Sub report). Sub-report seems to be
very slow in rendering? Also If I use List control, it does not allow
table inside list with out aggregate.
So I couldn;t use list control
Thanks,
VasanthSubreport is how you have to solve this. Make sure that you have appropriate
indexing so the subreport query runs quickly.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
<bvasanth123@.rediffmail.com> wrote in message
news:1137791468.342737.278100@.g47g2000cwa.googlegroups.com...
> Hi,
> My report requirement of customer activity report.
> For each customer, my report should show the summary by purchase
> catgory and then individual transaction details.
> Customer Name: Tom Tim
> Books: 100
> Computers : 2
> Others: 23
> (then all 125 transactions should be listed).
> Same summary and detail should be repeated for each customer in the
> same single report. (there are aound 200 customers)
> How can I achieve this? (other than Sub report). Sub-report seems to be
> very slow in rendering? Also If I use List control, it does not allow
> table inside list with out aggregate.
> So I couldn;t use list control
> Thanks,
> Vasanth
>|||The performance is very poor when we try to render in PDF. We checked
SP (in sub-report) which takes 1-2 seconds for each customer. But
rendering that takes more than 30 mins depending on data.|||Your question was initially about subreports. Based on what you want to do,
subreports are the way to do it. There are differences with rendering
different formats. HTML and CSV are very fast, PDF and Excel are much slower
(order of magnitude slower). Your hypothesis that the problem is the
subreports most likely is not the issue. The issue with PDF is either
complexity or the size of the data (number of rows and size of rows). Also,
do you have any images? If so, what format is the image in. Try the report
without images and see if that helps. If you want to know how much the
optimal time is then render it to html and see how long that takes. That is
the best case.
Is this for a user viewing on the screen or is this destined for printing?
If it is the user then try using drill through. Drill through is quite fast.
Also, does it have to be pdf? As I said, html is much faster.
RS does all rendering in memory. So you can also try adding additional RAM
to see if that would help.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
<bvasanth123@.rediffmail.com> wrote in message
news:1137851207.701517.281770@.g14g2000cwa.googlegroups.com...
> The performance is very poor when we try to render in PDF. We checked
> SP (in sub-report) which takes 1-2 seconds for each customer. But
> rendering that takes more than 30 mins depending on data.
>|||Thanks Bruces
1) Total records: 20,000 + ( 100 customer * 200 recods average)
2) This is purely for audit record keeping purpose. Not online report
3) We do not have any images
4) HTML report is coming quickly around 10 mins. PDF seems to be the
killer.. Takes for ever. (HTML size is ? 50 MB which we do not prefer)
5) We tried another sample report that just display 20,000+. PDF comes
in 5-10 mins. But if the same 20K+ records have been run with
sub-reports, it goes down in performance.
5) RAM is 4 GB|||RAM is fine. If it takes 10 mins for html and 30 for PDF then you are doing
pretty good. Usually the difference is greater than that. You might be able
to do something to get the data down quicker (playing with indexes) but that
would only affect at most 10 mins of the total time. The extra 20 minutes is
PDF rendering issues. My suggestion is to just schedule it to run at night.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
<bvasanth123@.rediffmail.com> wrote in message
news:1138029125.861955.154170@.o13g2000cwo.googlegroups.com...
> Thanks Bruces
> 1) Total records: 20,000 + ( 100 customer * 200 recods average)
> 2) This is purely for audit record keeping purpose. Not online report
> 3) We do not have any images
> 4) HTML report is coming quickly around 10 mins. PDF seems to be the
> killer.. Takes for ever. (HTML size is ? 50 MB which we do not prefer)
> 5) We tried another sample report that just display 20,000+. PDF comes
> in 5-10 mins. But if the same 20K+ records have been run with
> sub-reports, it goes down in performance.
> 5) RAM is 4 GB
>