从列中的表中选择所有内容

时间:2013-01-26 09:19:15

标签: sql sql-server sql-server-2008 tsql

我在阅读表格时使用此程序创建GUID号码。

存储过程正常运行,但只显示两列,idEventId

我需要在dbo.ASFC_App_Timetableid之外显示EventId的所有其他列。

其他列例如EventTitleEventNote

您是否能够为我提供解决此问题的代码示例?

 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

目前正在显示..我还需要显示其他列:

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

2 个答案:

答案 0 :(得分:2)

为什么不能在子查询中添加其他列?

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

答案 1 :(得分:1)

我认为这确实有用。

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

为什么您不使用NEWID()生成GUID

SELECT NEWID() Id
      EventId,
      EventTitle,
      EventNote
 FROM dbo.ASFC_App_Timetabl