This portal is to share my acquired knowledge related to Sql Server. I hope will be helpful for novice and professionals.

Saturday, July 28, 2012

Remove Milisecond from DateTime value.

I like to use following two ways to get rid of Milisecond from DateTime value:

Select GetDate()


1. Select CONVERT(Varchar,GetDate(), 120)

2. Select DateAdd(MS, -DatePart(MS,GetDate()), GetDate())

How to get Computed column definition ?

It is easy..using sp_Helptext system stored procedure we can get computed column definition .

Create Table ComputedColumn
(
AmountA INT,
AmountB INT,
AmountC AS (ISNULL(AmountA,0) + IsNull(AmountB,0))
)

INSERT INTO ComputedColumn
SELECT 1, 2

SELECT * FROM ComputedColumn

sp_Helptext ComputedColumn , AmountC 
 
OUTPUT
----------
(isnull([AmountA],(0))+isnull([AmountB],(0)))