SQL Tips



Retrieving Random Rows

Posted by on Dec 31, 2012 in SQL | 0 comments

You can run script below and it will give random rows every single time you run it:   USE AdventureWorks2012 GO -- Method 1 SELECT TOP 100* FROM SalesOrderDetail ORDER BY NEWID() GO -- Method 2 SELECT TOP 100 * FROM SalesOrderDetail ORDER BY...

read more

Removing Leading Zeros

Posted by on Dec 31, 2012 in SQL | 0 comments

Removing Leading Zeros From Column in Table   USE tempdb GO -- Create sample table CREATE TABLE Table1 (Col1 VARCHAR(100)) INSERT INTO Table1 (Col1) SELECT '000006' UNION ALL SELECT '00501007' UNION ALL SELECT '50401003' UNION ALL SELECT '0100 000 001' UNION ALL SELECT '00.0001' UNION ALL SELECT '07.001' GO -- Display the data from the new table SELECT * FROM Table1 GO -- Remove leading zeros SELECT SUBSTRING(Col1, PATINDEX('%[^0 ]%', Col1 + ' '), LEN(Col1)) FROM Table1 GO -- Clean up DROP TABLE...

read more

Tips to Speed up your database

Posted by on Dec 30, 2012 in SQL RESOURCES | 0 comments

10 SQL TIPS – to speed up your database http://www.catswhocode.com/blog/10-sql-tips-to-speed-up-your-database

read more

USEFUL SQL TIPS

Posted by on Dec 30, 2012 in SQL RESOURCES | 0 comments

This is a whitepaper of Top Ten SQL Performance Tips I found this to be a very useful link: http://www.quest.com/whitepapers/10_SQL_Tips.pdf

read more