Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My table is looking like this:

Id      name    disease     city        age     gender  zipcode
1	mani	flu	    chennai	34	*	6000**
2	arun	dyspepsia   chennai	28	*	6000**
3	deenu	flu	    vellore	23	*	6321**
4	naren	cancer	    vellore	24	*	6325**


i wanna disease column value shuffle randomly on my given table....how to make shuffle only disease on my table...

Actually i need my shuffle table like below :
Id      name    disease     city        age     gender  zipcode
1       mani    cancer      chennai     34        *     6000**
2       arun     flu        chennai     28        *     6000**
3       deenu    dyspepsia  vellore     23        *     6321**
4       naren    flu        vellore     24        *     6325**
Posted
Updated 17-Mar-13 21:52pm
v2
Comments
Anil Honey 206 18-Mar-13 4:05am    
Update database set disease ='cancer' where Id=1
like this update the database
Deenuji 18-Mar-13 4:07am    
i dont need to update i wanna to auto shuffle for those column values...if i insert again some values means it must return the auto shuffled values.....
Kuthuparakkal 18-Mar-13 5:06am    
check my solution given

Try this.....
Note:- Every run you get a different "disease"
SQL
WITH TCE_Shuffled AS
(
SELECT ROW_NUMBER() OVER (ORDER BY id ) AS ORIG_ROWNUM,
       ROW_NUMBER() OVER (ORDER BY NEWID()) AS NEW_ROWNUM,
      *
from dbo.myTableDis
)

select t1.id, t1.name, t2.disease, t1.city, t1.age, t1.gender, t1.zipcode
from TCE_Shuffled t1
join TCE_Shuffled t2
on t1.ORIG_ROWNUM = t2.NEW_ROWNUM



C#
private DataSet GetDataset()
{
    string connstring = "server=.;"
                        + "Trusted_Connection=yes;"
                        + "database=test; "
                        + "connection timeout=30";
    DataSet dataset = new DataSet();
    string queryString = "WITH TCE_Shuffled AS "
                        + " ("
                        + "  SELECT ROW_NUMBER() OVER (ORDER BY id ) AS ORIG_ROWNUM,"
                        + "          ROW_NUMBER() OVER (ORDER BY NEWID()) AS NEW_ROWNUM,"
                        + "         *"
                        + "   from dbo.myTableDis"
                        + "   )"

                       + "    select t1.id, t1.name, t2.disease, t1.city, t1.age, t1.gender, t1.zipcode"
                       + "    from TCE_Shuffled t1"
                       + "    join TCE_Shuffled t2"
                       + "    on t1.ORIG_ROWNUM = t2.NEW_ROWNUM";

    using (SqlConnection connection = new SqlConnection(connstring))
    {
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand(queryString, connection);
        adapter.Fill(dataset);
        return dataset;
    }
}
 
Share this answer
 
v3
Comments
Deenuji 18-Mar-13 6:56am    
thalaiva(leader) u r great.....
Deenuji 18-Mar-13 7:01am    
how i can implement this coding on my c# coding buddy?????? coz i don't know store procedure ....
Deenuji 18-Mar-13 7:21am    
k i can find the complete solution ...thank u....
Kuthuparakkal 18-Mar-13 7:28am    
updated solun, pls hav a look!
Deenuji 18-Mar-13 8:03am    
thank u alot sir...
You can't do that easily in SQL - it really isn't set up for that.
I would suggest that you do it in C#, by reading the data, manually shuffling it in a loop, and writing it back - there is no automatic mechanism to do this, each row is an independent object and does not know of the existence of any other row.
 
Share this answer
 
Comments
Deenuji 18-Mar-13 4:14am    
pls suggest some code to shuffle the column value in c# using loop sir.....
OriginalGriff 18-Mar-13 4:27am    
You are joking, right? You can't write a simple bit of code like that?
How would you read the data from the database?
Kuthuparakkal 18-Mar-13 5:06am    
Look at SQL solution added buddy! it works! no need of any coding
Maciej Los 18-Mar-13 4:28am    
+5!
Deenuji 18-Mar-13 4:28am    
s thank u ...sir i ll try
I presume you are trying to create sample data or mask production data. If it is sample data I think Red-Gate may have a tool for generating sample data.

For masking you are going to have to write a procedure to do that, as Griff said there is no tool to do it automatically.
 
Share this answer
 
As OriginalGriff wrote, you need to shuffle your data manually with C#.
See this: Random Class[^]. Change the code depends on your needs.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900