SQLTeam.com | Weblogs | Forums

Sql query


#1

Dear all,
Table,

Id name dob
1 gopal 10-16-1970

How to write a sql

Output,
Id name dob
1 g 10-16-1970
1 o 10-16-1970
1 p 10-16-1970
1 a 10-16-1970
1 l 10-16-1970


#2

why you want to do this?


#3
WITH
   tbl
   ( Id, name, dob )
AS
   (
   SELECT
      1
    , 'gopal'
    , Cast('1970-10-16' AS date)
   )
 ,
   nums ( num )
AS
   (
   SELECT
      t.n
   FROM
      (  VALUES
            ( 1 )
          , ( 2 )
          , ( 3 )
          , ( 4 )
          , ( 5 )) t ( n )
   )
SELECT
            tbl.Id
          , tbl.name
          , Substring(tbl.name, nums.num, 1) letter
          , tbl.dob
FROM
            tbl
CROSS JOIN  nums ;

Capture