You are on page 1of 2

select isdate('2006-2-28')

select getdate()

select convert(varchar,day(getdate()))

declare @testval int


set @testval = 6

select
case @testval
when 1 then 'first'
when 2 then 'second'
when 3 then 'third'
else 'other'
end

declare @testval int


set @testval = 5

select
case
when @testval <=3 then 'top 3'
else 'other'
end

cast and convert


the cast and convert functions are very similar: both translate a value from one
data type to another. although their performance is also similar, their syntax and
potential usage is slightly different.

both cast and convert have a straightforward syntax:

cast(expression as new_data_type)

convert(new_data_type, expression, [style])

public static void sum(int a, int b)


{
console.writeline("the sum of elements {0} and {1} is {2}",a,b,a + b);
}

public static void sumref(ref int a, ref int b)


{
a = 4;
b = 6;
console.writeline("the sume of elements {0} and {1} is {2}",a,b,a + b);
}

public static int sumout(int a, int b, out int sum1)


{

sum1 = a+b;
console.writeline("the sum1 of elements {0} and {1} is {2}",a,b,a+b);
return sum1;

select charindex('s','srinivasan')
select substring('srinivasan',1,9)

declare @a int
set @a=10
declare @b int
set @b = 20
declare @c int
set @c = @b / @a
print @c

You might also like