Thursday, 25 October 2012

practice session


select REPLACE('yjreddy','y','srisri')
select STUFF('yjreddy',1,10,'srisri')
SELECT QUOTENAME('abc.def')
select 'abc.def' as we
SELECT  'Happy '+ 'Birthday ' AS Result
select 'janardhana'+'Reddy' as fullname
select 'Microsoft'+'sqlserver' as Database1
select DIFFERENCE('yjreddy','yjreddy')
select LTRIM(RTRIM(' janardhana reddy yakkanti '))
SELECT RTRIM('Removes trailing spaces.   ');
select LTRIM('    yjreddy') as trimm
select '    yjreddy' as normal
select RTRIM(' yjreddy ')
select LTRIM(RTRIM(' yjreddy '))
 select  SWITCHOFFSET(GETDATE(),'')

 select ACOS(0.20)
 SELECT LTRIM(' Word ') AS Answer;



select LTRIM(R TRIM('                           yjreddy                      '))

select '            yjreddy         ' as Myname
select COS(90)
select TAN(45)
select @@PROCID
select SUSER_NAME()
select APP_NAME()
select @@ERROR


DECLARE @TestVal INT
SET @TestVal = 3
SELECT
CASE @TestVal
WHEN 1 THEN 'First'
WHEN 2 THEN 'Second'
WHEN 3 THEN 'Third'
ELSE 'Other'
END

DECLARE @TESTVAL123 INT
SET @TestVal123=10
select
CASE @TESTVAL123
when 1 then 'first'
when 2 then 'two'
else 'morethantwo'
end


DECLARE @STRINGVALUES varchar(50)
SET @STRINGVALUES='hi'
select
CASE @STRINGVALUES
when 'yjreddy' then 'yjreddy'
else 'gopireddy'
end

DECLARE @stringvals varchar(50)
set @stringvals='yjr'
select
CASE @stringvals
when 'jana' then 'jana'
when 'yjreddy' then 'yjreddy'
else 'yjr'
end


DECLARE @checkcondition int
set @checkcondition=10
select
CASE
when @checkcondition>5 then 'number is greater than 5'
else 'no is less than 5'
end


DECLARE @VALUETEST1 varchar(50)
set @VALUETEST1='jreddy'
select
case
when LEN(@VALUETEST1)>10 then 'length greater than 10'
else 'no within 10'
end


--cast and convert
DECLARE @Val1 CHAR(2) = '2';
DECLARE @Val2 INT = 3;
SELECT
  (@Val1 + @Val2) AS Total,
CASE
    WHEN ISNUMERIC(@Val1 + @Val2) = 0 THEN 'No'
    WHEN ISNUMERIC(@Val1 + @Val2) = 1 THEN 'Yes'
END AS IsNumber;

DECLARE @val123 VARCHAR(20)
DECLARE @val124 int
set @val123=50
set @val124=50
select
        (@val123+@val124) as Total
case
   
     WHEN ISNUMERIC(@val123+@val124)=0 then 'no'
     WHEN ISNUMERIC(@val123+@val124)=1 then 'yes'
     END as ISNumber

select cast(0.000000000000000000000000118 as real) as [cast result]
select convert(real, '-0.00000000000000000000000000000000000000118') as [convert result]

declare @d datetime
set @d='20001210 12:34:22'
select convert(varchar(10),@d,108)
declare @m money
set @m=23498
select convert(varchar(10),@m,1)
         

declare @i int
set @i=123456
select convert(char(5),@i),cast(@i as char(5))



SELECT



CAST('7/24/2010 12:00:00 AM' AS DATETIME)

SELECT



CONVERT(DATETIME,'7/24/2010 12:00:00 AM',103)
select CONVERT(DATETIME, '7/24/2010 12:00:00 AM')   AS [CONVERT]

select CONVERT(

 select   DATEDIFF("MM",'10/05/1987',getdate())
 select convert(varchar(20),getdate(),101)
 select CAST(GETDATE() as varchar(10))
 select CAST('101abcd' as varchar(20))

 DECLARE @Actualvalue int
 set @Actualvalue=100
 select Convert(varchar(30),@Actualvalue,101)
 end as isnumeric
 select COLLATIONNAME(,'yjr')
 select CURRENT_TIMESTAMP
select DATALENGTH('yjreddy')
DECLARE @Actualvalue int
 set @Actualvalue=100
 select Convert(varchar(30),@Actualvalue,101)
 end as isnumeric


 CREATE PROC testPrc (@val VARCHAR(10))

AS

BEGIN

 SELECT 1/@val AS operation

END







BEGIN TRY

 EXEC testPrc '0'

END TRY

BEGIN CATCH

 SELECT

 ERROR_NUMBER() AS ERROR_ID,

 ERROR_MESSAGE() AS ERROR_MSG,

 ERROR_SEVERITY() AS ERROR_SEVERITY,

 ERROR_STATE() AS ERROR_STATE,

 ERROR_PROCEDURE() AS ERROR_PROCEDURE,

 ERROR_LINE() AS ERROR_LINE()


GO


No comments:

Post a Comment