Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Label Printing Post Reply Post New Topic
Author Message
Bassline77
Newbie
Newbie
Avatar

Joined: 06 Feb 2009
Online Status: Offline
Posts: 21
Quote Bassline77 Replybullet Topic: Label Printing
     Posted: 01 Apr 2009 at 3:38am
Hi all,
I can find no where an answer to my question, please can anybody help.

I am printing labels for items from a db. In the db there is a list of items and a quantity field.

Basically what I want the report to do is: Print a label for each selected item on a new page, for each item in stock. So if the quantity field says there is 200 in stock there must be 200 labels printed for that item. Is there a function to set the number of copies like that in Crystal XI or can any one help me with a formula?

This report will be a stand alone report. So the user must just select the item and click on print.

Thanx in advance


Order out of chaoss
IP IP Logged
dazel
Newbie
Newbie


Joined: 31 Mar 2009
Location: India
Online Status: Offline
Posts: 6
Quote dazel Replybullet Posted: 02 Apr 2009 at 2:15am
Hi,
    I am not exactly sure of what you are talking but i am assuming that you want to at runtime generate 200 labels or say fields in the crystal report, if thats what you want than you will have to create parameterized crytal report where by you must generate the parameters at runtime in your code and add those parameters to your report at programatically.
i hope this helps you.Smile
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 02 Apr 2009 at 6:15am
Crystal will only report on what it sees.  So if in the database there is 1 record, it will report only once.
 
If you can create a stored procedure, you can use a loop to make 200 identical rows, and then Crystal will process the 200 rows (provided you set any options to eliminate duplicates).
 
You could pass in several item numbers from the crystal parameters, but you will need to parse them in the stored proc.  If the items are basically fixed, you could code that in stored proc.
 
Bottom line, you will need to figure out a way to create as many rows of data as there inidividual items to receive labels.
 
IP IP Logged
Bassline77
Newbie
Newbie
Avatar

Joined: 06 Feb 2009
Online Status: Offline
Posts: 21
Quote Bassline77 Replybullet Posted: 03 Apr 2009 at 4:18am
Ouch.... never worked with a stored proc before. Well guess its time to learn.
So the stored proc can create a number of records as there is in the quantity field and send that to crystal for detail lines. and I can just use 'new page after' to put each item on its own label.
Any recommends on some good reading regarding stored procs? I need to learn this quick.Confused
Thanx
Order out of chaoss
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 03 Apr 2009 at 6:19am
Sorry, I'm not much of a reader.
 
You will need to read about looping and temp tables I would guess.
 
As a rough outline, here is what I would do.
 
Select the information that you want to appear on the report into a temp table. Something like:
 
Select * into #temp from tablea
 
then create another temp table to hold the results with the duplicate records.  An easy way to copy the structure without having to use the create table command is:
 
Select * into #results from #temp where 1=2
 
since no records will match the 1=2 condition that table is created but without anything in it.
 
Now for the looping...
declare @loopCount INT
 
While Exists(Select * from #temp)
begin
  Select top 1 @loopCount = quantity field from #temp
  while @loopCount > 0
  begin
    insert #results
    select top 1 * from #temp
   
    set @loopCount = @loopCount -1
  end
 
  (now a hard part since there are multiple ways to delete)
 (if you are sql 2005 use:)
  DELETE TOP (1) FROM #temp
  (else)
  delete from #temp as t join (select top 1 * from #temp) as ss ON ss.uniquefield = t.uniquefield 
 
end
 
this should take the first record from the temp table and replicate it X times in the results table and then remove the first record from the temp.  You want to make sure that the field(s) in the 'On' statement are distinct enough to only delete the first record. It might be as simple as the item number, but it might be more complex, in which case you would add additional clauses using AND between the fields
 
Hopefully at this point we have a nice big results table, so let's see it...
 
SELECT * FROM #results
 
and that should give you the values that you want.
 
In crystal, you would find the stored proc that you just created and use that as a datasource.  You might need to set up an ODBC connection on your computer so that Crystal knows how to find the stored proc...but you probably already have that if you are connecting to a database
 
There's a lot to do, but once you get used to the stored proc, it is way more versatile than just connecting to tables.
 
 
 
IP IP Logged
Bassline77
Newbie
Newbie
Avatar

Joined: 06 Feb 2009
Online Status: Offline
Posts: 21
Quote Bassline77 Replybullet Posted: 03 Apr 2009 at 6:37am
Thank You very much for your comprehensive help. I will try this over the week end and i will let you know if it worked.
Order out of chaoss
IP IP Logged
Bassline77
Newbie
Newbie
Avatar

Joined: 06 Feb 2009
Online Status: Offline
Posts: 21
Quote Bassline77 Replybullet Posted: 07 Apr 2009 at 2:56am
Just to make sure I have done this correct, must it look something like this:
    CREATE PROCEDURE PROCLABLE
    AS
   
        Select * into #temp from RWGLIVE.MFGITM
        Select * into #results from #temp where 1=2

    declare @loopCount INT

While Exists(Select * from #temp)
   
        Select top 1 @loopCount = EXTQTY_0 from #temp
while @loopCount > 0
   

SET IDENTITY_INSERT #results ON

        insert #results
        select top 1 * from #temp

SET IDENTITY_INSERT #results OFF

        set @loopCount = @loopCount -1

        DELETE TOP (1) FROM #temp


SELECT * FROM #results
GO

What do i do after this, do i just connect to the SP with crystal and all my fields will be there?




Edited by Bassline77 - 07 Apr 2009 at 3:00am
Order out of chaoss
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 08 Apr 2009 at 7:33am
small changes
While Exists(Select * from #temp)
BEGIN   
        Select top 1 @loopCount = EXTQTY_0 from #temp
while @loopCount > 0
BEGIN

SET IDENTITY_INSERT #results ON

        insert #results
        select top 1 * from #temp

SET IDENTITY_INSERT #results OFF

        set @loopCount = @loopCount -1
END
        DELETE TOP (1) FROM #temp
END
 
Then yes, connect to the stored proc.  It shouldn't ask for any parameters, as the stored proc doesn't require any, and all of the fields from RWGLIVE.MFGITM should be displayed and ready for you to write a report against.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum