|
|
-
|
|
IF..ELSE clause in SQL Server is used for decision making. You can use it to run a set of statements based on certain conditions. The following are the examples on how to use it effectively for various purposes. Simple Decision making example
declare @status bit
set @status=1
if @status=0
prin......
|
|
|
|
-
|
|
For various reasons you may need to audit some activities on certain tables.Usually you can use triggers for this.Sometimes you may want to know the system from which data are added or the user who added data.In these cases, you can use two functions host_name() and user_name()
Host_name() This fun......
|
|
-
|
|
As you know well, VALUES clause is used to insert values to the table
A simple example is
declare @t table (id int , col1 int, col2 int, col3 int)
insert into @t values(1, 14, 12, 24)
select * from @t
But in version 2008, you can do more things using VALUES clause than the previous versions......
|
|
-
|
|
Sometimes back, my friend told me that they had an application where users update their timesheets. He suspected that some users who had access to the database directly update some entries. He wanted to know whether some users update entries using a query analyser and not using the application. You ......
|
|
-
|
|
Both these functions are used to convert values from one datatype to another But there are some differences between them 1 CAST is ANSI standard and CONVERT is specific to SQL Server 2 CAST can't be used for formating purposes. But CONVERT can be used for formating purposes particularly on datetime ......
|
|
-
|
|
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 ......
|
|
-
|
|
The symbol dot (.) plays a major role when you write queries It is mainly used to speicify the columns for the respective tables when a join is used as you see in the following example
select
t1.col1,t1.col2,t2.col3,t2.col4
from
table1 as t1 inner join table1 as t2 on t1.col1=t2.col1
......
|
|
-
|
|
''
Begin
Declare @str varchar(1000)
set @str='Exec Master..xp_Cmdshell ''bcp "Select * from '+db_name()+'..'+@table_name+'"
queryout "C:\data\'+@table_name+'.txt" -c'''
Exec(......
|
|
-
|
|
This post follows my previous three posts Part I
Part II
Part IIIBest practices when using datetime values
1 Always use proper DATETIME datatype to store dates This is very important becuase lot of people use varchar datatype to store formatted date values. Only if you use datetime datatype, you......
|
|