|
|
-
|
|
In the Query Analyser, set the Result mode to Text (Press CTRL+T) and run the following code
set nocount on
select
space(17-len(replicate(char(94),no)))+ replicate(char(94),no*2-1)
from
(
select top 10 row_number() over (order by name) as no from sysobject......
|
|
-
|
|
This is just for Fun. The following code is unformatted, unclear and may be confusing. But curious to know the result? Set the result mode of the query window to Text . While you are in Query Window press CONTROL+T and run the following code and see what it returns.
......
|
|
-
|
|
Though it is optional to execute a stored procedure without using EXEC or EXECUTE, it is needed when you use GO(or any other batch seperator) as the stored procedure name.
Create this procedure
create procedure GO
as
select 1 as number
Execute the procedure by
GO
It will not execute be......
|
|
-
|
|
Often deveopers confuse themselves between Timestamp and Datetime datatypes. But they are entirely different datatypes. Although the name has Time, the Timestamp datatype has nothing to do anything with date or time. Also you cannot explicitely add/update that column. It gets updated whenever data a......
|
|
-
|
|
Someone in the forums asked for finding out a string in which each character is same. Consider the following example
declare @t table(data varchar(20))
insert into @t
select '222222222222' as data union all
select '666666663466' union all
select 'aaaaaaaa'+CHAR(32) union all
select 'jjkjkhdg'......
|
|
-
|
|
You know that Create or alter procedure statement should be always in a seperate batch otherwise you will get an error "'CREATE/ALTER PROCEDURE' must be the first statement in a query batch." Sometime when you want to create or alter the procedure based on the existance of a procedure you may wonder......
|
|
-
|
|
Often people ask how to use InitCap function in SQL Server Initcap is used to capitalise each first letter of the word and keep rest as non-capital Pinal Dave has a post at http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-caseJoe Celko gave ......
|
|
-
|
|
Some people suggest usage of information_schema.routines View to view the definition of the procedure The problem is the datatype of that column is nvarchar(4000) and there is a chance that the definition gets truncated. So, the following wont give you full text of the definition
select routine_......
|
|
-
|
|
The Squeeze function is used to remove the multiple occurences of spaces into one occurence. In SQL Server there is no function to do the same. I needed to write this in my application to remove unwanted spaces in the string. Run the following and see the result
declare @t table(string_col varchar......
|
|
-
|
|
Sometimes we may need to extract only numbers from a string. Usually I see people using while loop to check each and every character to see if it is a number and extract it Here is a different approach
Declare @s varchar(100),@result varchar(100)
set @s='as4khd0939sdf78'
set @result=''
selec......
|
|