Posts Tagged ‘SQL’

How to select random row from a data table

1: Select a random row with Microsoft SQL Server: SELECT TOP 1 column FROM tableORDER BY NEWID() 2: Select a random record with Oracle: SELECT column FROM( SELECT column FROM tableORDER BY dbms_random.value )WHERE rownum = 1 3: Select a random row with MySQL: SELECT column FROM tableORDER BY RAND()LIMIT 1 4: Select a random [...]

Leave a Comment

How to get CSV file using SQL Server management studio

I had a task to output or generate CSV file using SQL Sever management Studio. After some searching and learning, I got the following steps to get my tasks done: 1: Open SQL Server Management Studio 2005.   Tools > Options > Query Results > SQL Server > General > Default destination for results;       Set [...]

Leave a Comment

The text data type cannot be selected as DISTINCT because it is not comparable

When I tried to select a table which includes a text type field using distinct. I got these error: The text data type cannot be selected as DISTINCT because it is not comparable The solution is convert text to VARCHAR(MAX). CONVERT(VARCHAR(MAX), text_type_filedname) Varchar(Max) is a LOB datatype and has a max size of 2GB.

Leave a Comment