Showing posts with label random. Show all posts
Showing posts with label random. Show all posts

Wednesday, March 28, 2012

How to assign random number to one column for 500 records?

I try to set up a testing sample table which contain one integer project_ID field for table Sample around 500 records, and want the project_ID to be random number within 1 to 99, how to implement script todo it?

thanks!

Here you go !
using System
namespace x {
classe y {
public y () {}
public int getRandomID () {
Random r = new Random()
return r.Next(1,99); // this indicates the start and end limit of the random function
}
}
}

then use the returned value into your SQL query to generate the records... make sure you dont have the project_ID as primary key as this above code does not check for uniqueness of the generated number....
HTH

Monday, March 26, 2012

How to append a new values like uniqueidentifiers, sequence numbers to data flow?

Hi,

I would like to know different possible ways in appending extra values like new uniqueidentifiers, sequence numbers, random number. Can you please tell what type of data flow components helps us ?

Append what to where? Do you want to add new columns with such vaues to a path within the data flow task?

Derived Column Transform?

Script Transform?

Row Number Transform ? (http://www.sqlis.com/default.aspx?77)

|||

yes..i want to append values to a path with in the data flow task.

If i use Derived Column Transformation, how can i generate uniqueidentifiers and sequence numbers for each row?

Thanks

Gopi

|||

For GUIDs you would need to use the script task, as there is no "New Guid" function in the expression syntax.

For sequence numbers or row numbers I assume, then again the script task is required. For an easier life you can use the cunningly named Row Number Transform I mentioned previously, which does just that, and comes as a simple MSI to install.

|||

Darren,

Thank you very much.

sql