Randomly select column data in SQL Server

Last Reply 10 months ago By dharmendr

Posted 10 months ago

Hi! I have table with data. I want random cells in result. 

DECLARE @QTable AS TABLE (Id INT,Name VARCHAR(10),nameone VARCHAR(10),nametwo VARCHAR(10),namethree VARCHAR(10),namefour VARCHAR(10))
INSERT INTO @QTable VALUES(1,'Suhrob','orange','apple','cherry','pear')
INSERT INTO @QTable VALUES(2,'Amonullo','oil','tomato','flour','meat')
select * from @QTable

Output result:

Id

Name

nameone

nametwo

namethree

namefour

1

Suhrob

cherry

orange

pear

apple

2

Amonullo

tomato

meat

oil

flour

Each time run script must change cells data.

For example: Input data into Table 

Id

Name

nameone

nametwo

namethree

namefour

1

Suhrob

orange

apple

cherry

pear

2

Amonullo

oil

tomato

flour

meat

 Output result:

Id

Name

nameone

nametwo

namethree

namefour

1

Suhrob

cherry

orange

pear

apple

2

Amonullo

tomato

meat

oil

flour