SQL and Database
Sunday, 23 December 2012
How to Generate Auto Increment IDs
DECLARE @Increment INT=1
DECLARE @NewProjectCode VARCHAR(100)
WHILE @Increment<100
BEGIN
SET @NewProjectCode='EMP'+ Right('0000'+CAST(@Increment as VARCHAR(4)),4)
PRINT @NewProjectCode
SET @Increment=@Increment+1
END
Wednesday, 12 December 2012
How to get random record from table in SQL
To get random record from table we use
NEWID
()
function. Example
USE
AdventureWorks
SELECT
TOP
1
*
FROM
Production
.
Document
ORDER
BY
NEWID
()
NEWID
()
is used to generate
UNIQUEIDENTIFIER
SELECT
NEWID
()
Newer Posts
Older Posts
Home
Subscribe to:
Posts (Atom)