stored procedures - How to render & insert alphabets row within the MS sql server records? -
i want represent record set using stored procedure.
i have many records likewise in ms sql database.
it listing record groupby a, b, c .. z wize..
automatically insert alphabets while got output sql table.
want below output procedure..
how possible using stored procedure..?
you can use left
, union
this, though still 3 columns row rows contains first letter:
create , populate sample table (please save step in future questions)
declare @t table ( name varchar(20), location varchar(20), createdon date ) insert @t values ('alex macwan', 'new york', '2015-12-10'), ('jone dinee', 'denmark', '2016-05-01'), ('jolly llb', 'usa', '2016-01-02'), ('amin mark', 'india', '2015-01-08'), ('ben denis', 'brazil', '2015-10-02')
the query:
select name, location, createdon @t union select left(name, 1), null, null @t order name
results:
name location createdon -------------------- -------------------- ---------- null null alex macwan new york 2015-12-10 amin mark india 2015-01-08 b null null ben denis brazil 2015-10-02 j null null jolly llb usa 2016-01-02 jone dinee denmark 2016-05-01
Comments
Post a Comment