How to generate a random number between a range in SSIS
I have a table Customer which contains 3 columns in it.1st is Customer name ,2nd is Customer phone number & 3rd column is blank. I have around 1200 unique records in my table.In 3rd column i want to insert data of Temperature they live.The Range of temp. must be 12 to 50. How to achieve it thriugh SSIS.I have Sql server 2008 R2 with me...! Its very Urgent..plz help me out Thanks in Advance.......
May 24th, 2012 12:39pm

I guess if it were me I would use a script transform to insert an extra column into the flow Declare this at the class level Random rnd = new Random(); Then use this in the process rows newcol = rnd.Next(1, 51); Chuck Pedretti | Magenic North Region | magenic.com
Free Windows Admin Tool Kit Click here and download it now
May 24th, 2012 12:45pm

Hi Chuck, I am very new to SSIS ,Can you plz explain step by step how to achieve this......?
May 24th, 2012 12:49pm

try this .. select [customer name],[customer phone],ABS(CHECKSUM(NEWID())) % 39 + 12 as temperature from Customer this will generate random number between range 12 and 50 Thanks and Regards, Sandhya
Free Windows Admin Tool Kit Click here and download it now
May 24th, 2012 1:18pm

1st add a script transform and connect it to your source 2nd open the script transform and go to the inputs and outputs page and create a new output column Then go to the script page and click the edit script button public class ScriptMain : UserComponent { Random rnd = new Random(); public override void Input0_ProcessInputRow(Input0Buffer Row) { Row.randomNumber = rnd.Next(1, 51); } } Chuck Pedretti | Magenic North Region | magenic.com
May 24th, 2012 1:32pm

You can modify your destination table executing this T-SQL against your destination database. Replace [YourTable] with your table name, and [TemperatureField] with its true name. There's no need to modify your SSIS package, just ignore the TemperatureField, it will be generated automatically by SQL Server at the moment it executes the INSERT statement. ALTER TABLE [YourTable] ADD CONSTRAINT [DF_YourTable_RandomField] DEFAULT (FLOOR(12.0+RAND()*39)) FOR [TemperatureField] Sebastian Sajaroff Senior DBA Pharmacies Jean Coutu
Free Windows Admin Tool Kit Click here and download it now
May 24th, 2012 1:48pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics