0

All the column that inside the select sql are needed to list out ,except the row_number(),any solution to eliminate to row_count ?

SELECT *
FROM
  (SELECT Station,
          ROW_NUMBER() over (
                             ORDER BY totalseq ASC) AS rownumber1
   FROM [SFCKM].[dbo].[T_DB_Subline]
   WHERE Track_Point_No = '3d1')a
LEFT JOIN
  (SELECT group_no,
          trim_line,
          MSC,
          lot_no,
          color,
          AON,
          format(Commit_time,'MM/dd/yy h:mm:ss tt')AS time,
          datediff(DAY,Commit_Time,SYSDATETIME()) AS aging,
          ROW_NUMBER() over (
                             ORDER BY commit_time DESC) AS rownumber
   FROM [SFCKM].[dbo].[T_Work_Actual]
   WHERE Track_Point_No = '3d1') c ON a.rownumber1 = c.rownumber
ORDER BY a.rownumber1
  • Select station , row_number() over (order by totalseq asc) can i just select the station column only? please help – Doomhammer Feb 27 '14 at 08:12
  • 1
    The query you have posted does not work. `Msg 102, Level 15, State 1, Line 5 Incorrect syntax near '*'.` Post what you have that works but don't give the result you want. Also post some sample data and the expected output using that data. – Mikael Eriksson Feb 27 '14 at 08:18
  • sorry i had re-post the complete code without error(please check it as well) , all the column are need to list out expect the row_number() – Doomhammer Feb 27 '14 at 08:32

2 Answers2

1

You could just select the values you are looking for e.g. Station and aging.

select a.Station, c.aging from                   
    (select Station, ROW_NUMBER() over (order by totalseq asc) AS rownumber1 
    from [SFCKM].[dbo].[T_DB_Subline] where Track_Point_No = '3d1') a
    left join
    (*,aging,ROW_NUMBER() over (order by commit_time desc) AS rownumber
    FROM [SFCKM].[dbo].[T_Work_Actual] where Track_Point_No = '3d1') c
on a.rownumber1 = c.rownumber
order by a.rownumber1
Mathias
  • 5,642
  • 2
  • 31
  • 46
  • sorry i had re-post the complete code without error(please check it as well) , all the column are need to list out expect the row_number() – Doomhammer Feb 27 '14 at 08:31
  • Thanks you my problem is solve i do in << select a.Station,c.* from (select Station, ROW_NUMBER() over ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ...............>> – Doomhammer Feb 27 '14 at 08:44
1

Don't use SELECT *: specify only the columns you need. SELECT * is not best practice, just lazy

There is no way to exclude a column as per my answer SQL exclude a column using SELECT * [except columnA] FROM tableA?

Community
  • 1
  • 1
gbn
  • 422,506
  • 82
  • 585
  • 676