Live Traffic Feed

Thursday, October 11, 2018

Generate 8 digit random alphanumeric string in sql server

Leave a Comment
For generate random alphanumeric string in sql server, use following query:


SELECT CAST((ABS(CHECKSUM(NEWID()))%10) as varchar(1)) + CHAR(ASCII('a')+(ABS(CHECKSUM(NEWID()))%25)) + CHAR(ASCII('A')+(ABS(CHECKSUM(NEWID()))%25)) + left(NEWID(),5)


This will return alphanumeric string with 8 digit.

If you want to use this query to sql server function then refer my another blog from following link:

Use NEWID() in sql server function
Read More

Wednesday, October 10, 2018

How to use NEWID() in sql server function

Leave a Comment
Sql server function not allow to use NEWID() function.

Solution:
-> Create view in same database from following query:

CREATE VIEW [dbo].[GetNewID] AS SELECT NEWID() AS new_id

Now you can use SELECT new_id FROM [dbo].[GetNewID] instead of NEWID() in your query in sql server function.
Read More