Reputation: 73908
I am using this procedure to create a GUID
number when reading a table.
The stored procedure works correctly, but displays only two column, id
and EventId
.
I need to display all the other columns of dbo.ASFC_App_Timetable
beyond id
and EventId
.
Other columns are EventTitle
and EventNote
for example.
Are you able to provide me a sample of code for solving this issue?
CREATE PROCEDURE SPROCGetAllEventsForStudent
AS
BEGIN
SELECT convert(uniqueidentifier,
stuff('62799568-6EF2-4C95-84E7-4953A6959C99',1,len(rn),convert(varchar,rn))) id,
T.EventId
FROM (
select x.EventId, ROW_NUMBER() over (order by x.EventId) rn
FROM dbo.ASFC_App_Timetable as x ) T
END
At the moment is displays.. I need to display the other columns, too:
22799568-6EF2-4C95-84E7-4953A6959C99 AB-TT-E1-2/TU12
32799568-6EF2-4C95-84E7-4953A6959C99 PU-A2-2 -Z/CL12
42799568-6EF2-4C95-84E7-4953A6959C99 PU-A2-2 -Z/CL12
52799568-6EF2-4C95-84E7-4953A6959C99 PU-A2-2 -Z/CL12
62799568-6EF2-4C95-84E7-4953A6959C99 PU-A2-2 -Z/CL12
72799568-6EF2-4C95-84E7-4953A6959C99 PU-A2-2 -Z/CL12
82799568-6EF2-4C95-84E7-4953A6959C99 PU-A2-2 -Z/CL12
Upvotes: 0
Views: 77
Reputation: 33381
I think this does work.
SELECT EventTitle,
EventNote,
convert(uniqueidentifier,
stuff('62799568-6EF2-4C95-84E7-4953A6959C99',1,len(rn),convert(varchar,rn))) id,
T.EventId
FROM (
select x.EventId,
EventTitle,
EventNote,
ROW_NUMBER() over (order by x.EventId) rn
FROM dbo.ASFC_App_Timetable as x
) T
Why you don't use NEWID()
to generate GUID
?
SELECT NEWID() Id
EventId,
EventTitle,
EventNote
FROM dbo.ASFC_App_Timetabl
Upvotes: 1
Reputation: 263683
why can't you add the other columns in the subquery?
SELECT convert(uniqueidentifier,
stuff('62799568-6EF2-4C95-84E7-4953A6959C99',1,len(rn),convert(varchar,rn))) id,
T.EventId,
T.EventTitle ,
T.EventNote
FROM
(
select x.EventId,
x.EventTitle ,
x.EventNote,
ROW_NUMBER() over (order by x.EventId) rn
FROM dbo.ASFC_App_Timetable as x
) T
Upvotes: 2