Monday, August 13, 2012

found some useful sql tips


·      Insert multiple rows
insert into tablename (col1, col2)
select ‘this1’, ‘that1’
union all
select ‘this2’, ‘that2’
union all
select ‘this3’, ‘that3’
union all
select ‘this4’, ‘that4’
From Personal Notes of Pinal Dave


·         Conditional Where Clause
select *
from   dbo.tblConditionalWhereClause
where  ((Businessdate = @BusinessDate) and (_NODEID_ = @nodeID))
              or     ((@BusinessDate is null) and (_NODEID_ = @nodeID))
              or     ((@nodeID is null) and (Businessdate = @BusinessDate))
              or  ((@BusinessDate is null) and (@nodeID is null))
logical where clause (Not A) or B means if A then B

No comments:

Post a Comment