Question

Sybase IQ generating distinct rows for dummy table

Asked by: SybaseUk

Hi,

I am trying to generate a table containing 25 columns and populate with some sample data. My aim is to get around 300k rows. I have generated the table with 300 distinct rows of sample data using powerdesigner. Does anybody know a nice way of blowing up this table to 300k rows without duplicating any of the data?? I tried using the STUFF function to take the last 2 digits of the ID and append to each column as follows: -

insert into test1 (C1)
select  stuff(C1,5,2,substring(convert(char, ID), length(convert(varchar, ID))-1,2))
from test1

But this method gives me duplicate values when I execute distinct count. Can some1 please help?

But this

create table TEST1 (
   ID                   int                            null default autoincrement,
   C1                   char(6)                        null,
   C2                   char(6)                        null,
   C3                   char(6)                        null,
   C4                   char(6)                        null,
   C5                   char(6)                        null,
   C6                   char(6)                        null,
   C7                   char(6)                        null,
   C8                   char(6)                        null,
   C9                   char(6)                        null,
   C10                  char(6)                        null,
   C11                  char(6)                        null,
   C12                  char(6)                        null,
   C13                  char(6)                        null,
   C14                  char(6)                        null,
   C15                  char(6)                        null,
   C16                  char(6)                        null,
   C17                  char(6)                        null,
   C18                  char(6)                        null,
   C19                  char(6)                        null,
   C20                  char(6)                        null,
   C21                  char(6)                        null,
   C22                  char(6)                        null,
   C23                  char(6)                        null,
   C24                  char(6)                        null,
   C25                  char(6)                        null
);
 
insert into TEST1 (C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15, C16, C17, C18, C19, C20, C21, C22, C23, C24, C25) values ('H0A9HT', 'SGYO53', '27V8L2', '9EM508', ' MX12I', '5KP34L', '2S40AO', '2XIYW6', '0G5COU', 'T2QLOI', '4AQXA8', 'YIA80X', ' 6L8S2', 'IFR7NN', '8223LK', 'XHEKTW', '304GVR', 'W EMVT', '08G1JX', 'LT3CVB', 'GT38TX', '21DHHX', '5MKAWW', 'BNCISN', '1XDDJ2');
 
insert into TEST1 (C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15, C16, C17, C18, C19, C20, C21, C22, C23, C24, C25) values ('RU812M', 'M6 7WG', '3HUU4A', 'QU55G9', 'RJMNOY', 'WRDJMH', 'V8KGCT', 'UWONM1', '6C3O Q', '9Y  6G', '2H927L', 'TVUT U', 'R5RG0N', '9SUJ37', 'VTOO2Y', '4XPLMN', 'OLMPU8', 'WU6VLD', 'P70A3X', ' 12VPO', '0MI3TX', 'G2E1W2', 'NNBMI5', 'NOH5C9', '73MKPD');

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-05-06 at 03:11:25ID24384229
Tags

Sybase IQ Transact SQL

Topic

Sybase Database

Participating Experts
2
Points
500
Comments
32

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. SQL Distinct
    I want to pull a number of records with that are not distinct but i want only one record from each distinct time stamp. how would i write the SQL statement?
  2. NOT DISTINCT
    Is there such a thing as SELECT NOT DISTINCT?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: alpmoonPosted on 2009-05-06 at 04:23:58ID: 24313274

You can use rand() function for that purpose. There is a short article about the usage:

http://www.sybase.com/detail?id=648

You can develop a similar loop to create rows.

 

by: SybaseUkPosted on 2009-05-06 at 04:56:58ID: 24313517

Hi,

Thanks for that info. How would I create the loop to insert new rows (i.e. double the rows with distinct values) instead of updating the existing column values?

Thanks!

 

by: alpmoonPosted on 2009-05-06 at 05:45:59ID: 24313973

Just as an example:

declare @max int
declare @cur int

select @cur = 1, @max = 300000 -- test with a smaller number first as I haven't tested it

while @cur < @max
begin

insert into TEST1 values (str(rand()), str(rand(@cur)), str(rand()), ....)

select @cur = @cur + 1

end

You can use different seed values to manipulate random generator as well, I just put @cur as seed as an example.

 

by: grant300Posted on 2009-05-06 at 06:46:23ID: 24314689

You have another problem as well.  Doing 300K individual inserts in Sybase IQ will take a very long time.  IQ simply is not made for fast individual record manipulation.

If you have to do all this inside IQ, create the table without any indexes (except the default FPs of course) and populate it.  Start with a few thousand rows of random data.  For now, leave the IDs blank.  Then, use INSERT/SELECT to double the number of rows each time.  If you start with 9375 seed rows and double it 5 times, you will wind up with 300K.

After you have all the rows you need, you can go back and assign the IDs in bulk.    You can either use something like UPDATE table SET IDcol = NUMBER(*).  Alternatively, you can use the ROWID with something like... UPDATE table SET IDcol = ROWID(table).  Of course, if you need a character prefix or something else, you can add that into the expression you use in the UPDATE

Of course, you can always use scripts or another database (ASA or ASE) to generate the data, BCP it out and do a LOAD TABLE to get it into IQ.

Regards,
Bill

 

by: SybaseUkPosted on 2009-05-07 at 01:53:53ID: 24323477

Hi Bill,

Many thanks for your reply. As always, your help is very much valued & appreciated.

Its a little more tricky, because my table has 25 columns which are char(6). I designed it with powerdesigner and also used PD to generate 300 rows of sample data. I have been using INSERT/SELECT to double the rows within IQ but the problem is that I end up with duplicate rows. I then tried to use RAND() within my INSERT/SELECT statement but I am still ending up with duplicate rows.

insert into test1 (C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15, C16, C17, C18, C19, C20, C21,
C22, C23, C24, C25)
select  stuff(C1,5,2,substring(convert(char, rand()), 2,2))
select  stuff(C2,5,2,substring(convert(char, rand()), 2,2))
select  stuff(C3,5,2,substring(convert(char, rand()), 2,2))
........................
etc

Running this statement twice now gives me 1200 rows with only 900 distinct values in each column.

select top 5 c1 from test1

c1
'H0A9HT'
'RU812M'
'FACK8O'
'UBC86S'
'3REOAK'

select top 5 c1 from test1 where ROWID("Test1") > 300

c1
'H0A9.5'
'RU81.5'
'FACK.5'
'UBC8.5'
'3REO.5'

select top 5 c1 from test1 where ROWID("Test1") > 600

c1
'H0A9.9'
'RU81.9'
'FACK.9'
'UBC8.9'
'3REO.9'

select top 5 c1 from test1 where ROWID("Test1") > 900

c1
'H0A9.9'
'RU81.9'
'FACK.9'
'UBC8.9'
'3REO.9'

Any ideas why my data is being duplicated and not giving me different values using the rand() function???

Thanks

 

by: SybaseUkPosted on 2009-05-07 at 08:11:20ID: 24326771

applmoon,

I need to use stuff to append the first 2 s.f's of the generated random value to the existing column C1, C2, C3 respectively.....

So I can't use literal values, I must use INSERT/SELECT. However, I am still getting duplicates........

 

by: grant300Posted on 2009-05-07 at 09:27:33ID: 24327596

You were not specific about what you wanted.  If I understand correctly, you want each value in each of the 26 columns to be unique across all 300,000 rows.

Using a RAND function will not guarantee any degree of uniqueness at all.  How could it?  They are random numbers.  It is a bit like rolling a die (one dice) six times and expecting to get a 1, 2, 3,, 4, 5, and 6.  It ain't likely to happen; roughly a 1 in 65 chance (precisely 5*4*3*2 in 6^5 chances).

You might want to examine your real requirements.  It would be very unusual for there to be 300,000 rows of 26 six character values and not have any duplicates.  Unless you are generating lottery tokens or something, real life will give you dupes much as you are getting with your random number generation.

If you really need each value to be unique, you will have to create each and every value explicitly.  26 columns cries out for each column to begin with a character of the alphabet.  The remaining 5 characters can be a zero-padded hex number.  You can adjust the starting offset for each one so they are not in total lockstep; you have plenty of room since 5 hex digits gives you just over 1 million possible values.

So what I would do is create the list of numbers from 1 to 300,000, then generate each column value from that by adding the column prefix (A-Z) and calculating a hex number from the ID (1-300000) and the offset for that column.

You can do this by creating a single column table with the IDs and a helper table with 26 columns of INT and the offset for each one.  You can then generate the entire target table in an INSERT/SELECT by joining your ID table with the Column Offset table and using an expression to generate each column value, e.g.

INSERT INTO TargetTable
SELECT ID,
               'A' + RIGHT(INTTOHEX(ID+CS.COL_A),5),
               'B'.........
FROM ID_Table,
           Column_Offset CS

Regards,
Bill

 

by: alpmoonPosted on 2009-05-07 at 16:54:00ID: 24331917

I agree that "Using a RAND function will not guarantee the uniqueness". But possibility of uniqueness depends on how that function is used. A dice has 6 sides, a two digit number has only 99 possibilities. If you use rand function 6 times to generate 6 different characters, you would have 308,915,776 possibilities and the chance of uniqueness would be high enough even though it is not guaranteed.

I think using some seed rows is not a good idea.

 

by: grant300Posted on 2009-05-07 at 17:53:41ID: 24332168

The problem is that the procedure SybaseUK is using does not generate six individual random characters for each of the 25 fields for each row.  It looks as if he is simply stuffing a couple of characters in.  Besides, if you did try calling RAND 150 times for each row, I suspect there would be a performance issue.  I am pretty sure that RAND is an ASA function, not an IQ function, so all the data would have to pass back and forth between the two engines.  This kind of thing should be better documented in IQ but as of now it is more experiencial than anything else.

Bottom line, if you need guaranteed uniqueness, you cannot use random functions.

Regards,
Bill

 

by: alpmoonPosted on 2009-05-07 at 22:07:51ID: 24333148

I might be wrong, but my understanding is this is a one off process to run and prepare a sample data for a test. So performance shouldn't be an issue. Also data can be prepared on another server and then loaded into IQ. Also if it is the case and there are a few duplicate rows, they can be deleted.

You are right saying that instead of using seed rows generating all rows at once would be a better approach. I am not really sure whether using rand function to create six character data is easier or your method is easier. But, I think they are both valid methods.

There might be around 300 duplicate rows out of 300K rows when rand() is used, but they can be deleted easily. Also it depends on how many charaters are used. If small caps and numbers are used, the possibility of uniqueness would be much higher.

 

by: SybaseUkPosted on 2009-05-08 at 01:37:22ID: 24334032

Hi alpmoon,

I have tried using the loop method you have suggested but I am still getting the same results as I did without the loop. Can you please look at my code and tell me whats wrong?

declare @max int
declare @cur int
declare @char char(2)

select @cur = 1, @max = 3

while @cur < @max
begin
select @char = substring(convert(char, rand(@cur)),2,2)

insert into Test1 (C1)
select
stuff(C1,5,2,@char) from Test1

select @cur = @cur + 1

end

As you can see I am using stuff to append the last 2 random numbers to replace the last 2 characters of C1. I cannot use literal values therefore I am using INSERT/SELECT...

Any help appreciated please....

 

by: SybaseUkPosted on 2009-05-08 at 01:47:16ID: 24334073

Hi Bill,

alpmoon is right in that the sample data does not need to 100% unique and I agree with him. However, the loop method isn't working presently and I am stuck. I desperately need to get around 300k rows and as alpmoon suggested, I can easily remove any duplicates.

The problem I am facing is that the rand() function is not producing random values which I can then stuff into C1, C2, C3 etc....

 

by: alpmoonPosted on 2009-05-08 at 04:41:02ID: 24335022

I think the main issue is rand() generates a number between 0 and 1. So you should multiply that number and find a way to convert it to a character. One way of doing it:

@char1 = char(rand()*100000) % 26) + 65)

This should produce a character between A and Z. I haven't tested it. Some corrections might be needed.

Then you can repeat this in the loop:

declare @max int
declare @cur int
declare @char2 char(2)

select @cur = 1, @max = 3

while @cur < @max
begin
select @char2 = char(rand()*100000) % 26) + 65)+char(rand()*100000) % 26) + 65)

insert into Test1 (C1)
select stuff(C1,5,2,@char2) from Test1

select @cur = @cur + 1

end

But, you can also repeat it six times to generate the whole string:

select @char6 = char(rand()*100000) % 26) + 65)+char(rand()*100000) % 26) + 65)+char(rand()*100000) % 26) + 65)+char(rand()*100000) % 26) + 65)+char(rand()*100000) % 26) + 65)+char(rand()*100000) % 26) + 65)

and insert it rather than using insert .. select

 

by: SybaseUkPosted on 2009-05-08 at 04:43:33ID: 24335031

Bill you are correct that RAND() will not guarantee uniqueness but a combination of 25 columns with random values appended should be unique (across a single row)....

INSERT/SELECT is doing this process in batches of 300 and thats the reason I think I am not getting a true random value. I need a way of stuffing a new random value (even though there are only 99 possibilities) into the respective columns for every row.

Can you suggest any solution please?

P.S. I'm just trying to generate a modest size table for testing purposes...

 

by: alpmoonPosted on 2009-05-08 at 05:26:57ID: 24335289

Now, I understand what you want better. If you only want to generate only two digit, you should multiply the result of rand() with at least 100:

insert into test1 (C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15, C16, C17, C18, C19, C20, C21,
C22, C23, C24, C25)
select  stuff(C1,5,2,substring(convert(char, rand()*100), 2,2))
select  stuff(C2,5,2,substring(convert(char, rand()*100), 2,2))
select  stuff(C3,5,2,substring(convert(char, rand()*100), 2,2))
....

or use module additionally:

insert into test1 (C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15, C16, C17, C18, C19, C20, C21,
C22, C23, C24, C25)
select  stuff(C1,5,2,substring(convert(char, rand()*100000 % 100), 2,2))
select  stuff(C2,5,2,substring(convert(char, rand()*100000 % 100), 2,2))
select  stuff(C3,5,2,substring(convert(char, rand()*100000 % 100), 2,2))
......

 

by: grant300Posted on 2009-05-08 at 08:50:02ID: 24337306

alpmoon,

Yeah, this gets a log clearer now that we know sybaseUK does not each column value to be unique; just the entire row.

That code will work 90 percent of the time but you still have a problem with single digit numbers.  You need to ensure there is a leading zero or you will wind up with about 10 percent of the values being too short.

Try...
select stuff(C1,5,2,right('0'+convert(varchar,rand()*100000 % 100),2))

Come to think of it, STUFF is slower than substring and concatenation.  We could use...
select substring(C1,1,4)+right('0'+convert(varchar,rand()*100000 % 100),2)

Finally, instead of 100000, I would choose a prime number in that vicinity.  Something tells me you'll get better (more random) results than using a multiplier that is an even multiple of the modulo.

Regards,
Bill

 

by: SybaseUkPosted on 2009-05-09 at 03:41:42ID: 24343217

hi guys,

i was trying to convert the rand() output to char and then take a substring of that i.e. 2 digits and stuff it into C1.

so for example:

select stuff('H0A9HT', 5,2,substring(convert(char, rand()), 2,2))

would produce the result:

H0A935

the last 2 digits being random values

 

by: SybaseUkPosted on 2009-05-11 at 02:26:38ID: 24352744

Hi,

I get a syntax error from executing the following statement: -

select stuff(C1,5,2,right('0'+convert(varchar,rand()*100000 % 100),2))

If I remove % 100 then the statement executes but I dont think its doing what it should be????

select stuff(C1,5,2,right('0'+convert(varchar,rand()*100000),2))

 

by: grant300Posted on 2009-05-11 at 06:42:00ID: 24354448

The text of the syntax error might be useful but I think I know what the issue is.

The modulo operator only works on integers.  You will have to add a CONVERT(INT,..... to the expression to get it to function properly.

You know, since you are going to grab two digits by position and then convert them into a string anyway, why bother with the modulo.  Try something like....

select stuff(C1,5,2,substring(convert(varchar,rand(),3,2)))

Regards,
Bill

 

by: SybaseUkPosted on 2009-05-11 at 08:02:55ID: 24355372

Hi Bill,

This is what I began with!

I appreciate that I will get some column values which will be duplicates but the chances of the entire row being a duplicate (or identical) should be should be very less likely. But I am getting many rows which are completely identical so I know there is a bug in my code or the loop.

I was thinking the purpose of the loop is to do single row by row inserts and thus giving me a true random value each time. But I am not doing single row by row inserts, rather I am doubling the amount of rows.

How do I do single row by row inserts but only change/replace the last 2 characters of each value with a random value????

This is getting very frustrating now.

Thanks for all your help.  

 

by: SybaseUkPosted on 2009-05-11 at 09:22:41ID: 24356246

Hi Guys,

Please disregard all the previous messages. I have decided to scrap my 300 rows of sample data and start from scratch.

My table has an ID (auto-identity) column and 25 columns of char(6). I would like to populate this table with random data and have atleast 300k rows that are unique....please advise the best way to go about

many thanks!

 

by: alpmoonPosted on 2009-05-12 at 00:34:05ID: 24361969

I am correcting the syntax there:

declare @max int
declare @cur int
declare @char6 char(6)

select @cur = 1, @max = 300

while @cur < @max
begin
select @char6 = char((rand()*100000 % 26) + 65)+char((rand()*100000 % 26) + 65) +
  char((rand()*100000 % 26) + 65)+char((rand()*100000 % 26) + 65) +
  char((rand()*100000 % 26) + 65)+char((rand()*100000 % 26) + 65)

insert into Test1 (C1)
select @char6

select @cur = @cur + 1

end

I have tested it for one column and it works fine(covers A to Z). You can repeat @char6 variable as many as you can.

 

by: SybaseUkPosted on 2009-05-12 at 01:49:25ID: 24362338

alpmoon,

I have tried the above and I get a syntax error. If I execute this on its own: -

select char((rand()*100000 % 26) + 65)

I get syntax error near '(end of line)' message. Please help me resolve this.

 

by: SybaseUkPosted on 2009-05-12 at 02:54:34ID: 24362695

Hi guys,

I now have the following and it works fine but it takes a very long time and also eventually runs out of space. Is there a quicker way of doing this?

declare @max int
declare @cur int
//declare @char6 char(6)

select @cur = 1, @max = 100000

while @cur < @max
begin


insert into Test1 (C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15, C16, C17, C18, C19, C20, C21,
C22, C23, C24, C25)
select stuff(inttohex(convert(int,rand()*100000)),1,3,'A'),
       stuff(inttohex(convert(int,rand()*100000)),1,3,'B'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'C'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'D'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'E'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'F'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'G'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'H'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'I'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'J'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'K'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'L'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'M'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'N'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'O'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'P'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'Q'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'R'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'S'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'T'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'U'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'V'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'W'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'X'),
 stuff(inttohex(convert(int,rand()*100000)),1,3,'Y')

select @cur = @cur + 1

end

 

by: SybaseUkPosted on 2009-05-12 at 03:16:43ID: 24362832

Do you think it would be easier to write a shell script to create a data file containing delimited rows and then load these into IQ???

Can anyone please help me write a C shell script to create a test data file??

Thanks,

 

by: SybaseUkPosted on 2009-05-12 at 03:37:48ID: 24362967

P.S. I need your help to write a shell script that will create the data (300K rows) each containing a unique id and random data made up of 25 columns of char(6).....

Please let me know whether I shud ask a new question and I would be happy to do that....

Many Thanks,

 

by: alpmoonPosted on 2009-05-12 at 03:39:53ID: 24362988

Actually the code I have tested was for ASE. If you have an ASE server. You can extend it for 25 columns and run for 300K rows. Then bcp out the data and insert into IQ. Inserting data into IQ one row at a time is not a good idea at all as Bill said before.

Or if you have ASA, you can do it in ASA as well. If you don't both, directing output to a text file and then eliminating unnecessary lines and tabs by sed might be a better option without writing a shell script.

 

by: grant300Posted on 2009-05-12 at 11:36:54ID: 24367802

All I can do is repeat my suggestion from early in the thread....

So what I would do is create the list of numbers from 1 to 300,000, then generate each column value from that by adding the column prefix (A-Z) and calculating a hex number from the ID (1-300000) and the offset for that column.

You can do this by creating a single column table with the IDs and a helper table with 26 columns of INT and the offset for each one.  You can then generate the entire target table in an INSERT/SELECT by joining your ID table with the Column Offset table and using an expression to generate each column value, e.g.

INSERT INTO TargetTable
SELECT ID,
               'A' + RIGHT(INTTOHEX(ID+CS.COL_A),5),
               'B'.........
FROM ID_Table,
           Column_Offset CS

This will do all the inserts in one pass and be at least 100 and probably closer to 1000 times faster than the individual inserts you were doing.

How you create the ID_Table rows is irrelevant.  You could create a list of 300000 numbers in a shell script, stuff it in a flat file, and then do a LOAD TABLE to get it in.

Regards,
Bill

 

by: SybaseUkPosted on 2009-05-13 at 02:49:56ID: 24372870

Hi,

I have now inserted the data into ASE and I have unique rows of data...

I want to bcp the data out and have it pipe delimited and row delimited by new line. Can you please show me how I can format the data so it is pipe delimited and row delimited by new line? I am using windows.....

I will then load this flat file into IQ

Thanks,

 

by: SybaseUkPosted on 2009-05-13 at 04:17:08ID: 24373425

Hi,

Can anybody explain why a simple query like the following takes around 6 seconds in ASE but is taking around 4 mins in IQ????????????

select C1, count(*)
from test1
group by C1
having count(*) > 1

I have loaded the IQ table by generating the random data in ASE and BCP'ing the data out. I am very confused why it is taking so long for this query to run.....

Can some1 please have a look at my query plan also and help me?

  • queryplan.doc
    • 226 KB

    Word doc containing the query plan for the above query

 

by: grant300Posted on 2009-05-13 at 08:40:11ID: 24376165

That one sounds like a whole new topic and question.  Why don't you close off this one an open a new one.  Give the points to Alpmoon.

Regards,
Bill

 

by: SybaseUkPosted on 2009-05-13 at 08:42:27ID: 31578379

I am splitting the points 50/50 as both of you participated equally in the final solution..

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...