Archive for the ‘SQL Functions’ Category

How to make fixed length digit

this is one of the easy posts for me i will talk about how to fixed length digit . means i have column stored in the DB and i want to show hime with fiexd lenght like “00001 or 00123” that is pretty much easy using one of the sql functions Called STUFF this function […]

More »

SQL Server – REPLICATE function (repeat string N numbers of times)

REPLICATE function this is one of the sql server string functions. This function repeat string or char N number of time REPLICATE ( string_expression ,integer_expression ) Example. DECLARE @st VARCHAR(10)=’@1′; SELECT Replicate(@st,4) The result. @1@1@1@1

More »

SQL SERVER – Using Group by With Rollup (Transact-SQL)

Generates the simple GROUP BY aggregate rows, plus subtotal or super-aggregate rows, and also a grand total row. The number of groupings that is returned equals the number of expressions in the plus one. For example, Consider the Following statement. SELECT a, b, c, SUM (EXPRESSION) FROM T GROUP BY ROLLUP; Here is an example. […]

More »

Get the next value of identity column

We are as programmers it is used to make Primary Key for table as Identity. Now if we want to pre know the next value that will be assigned when inserting new row, We can achieve that by calling SQL Function “IDENT_CURRENT” that get the current Value for the Primary Identity Column. SELECT IDENT_CURRENT (’dbo.TableName’) […]

More »