0

Need to write the result to a table

select
    convert(datetime, dbo.time(table1.col1)) 
from 
    table1
order by 
    col1
new_user
  • 1
  • 1
  • 1
    Do you consider [computed column](https://learn.microsoft.com/en-us/sql/relational-databases/tables/specify-computed-columns-in-a-table?view=sql-server-ver15) or view? – Leszek Mazur Jun 02 '20 at 04:38
  • @LeszekMazur computed column will work. Because, I am trying to further perform small operations on the resulting table – new_user Jun 02 '20 at 04:39

2 Answers2

0

Temp table (no order by):

SELECT
    CONVERT(SMALLDATETIME, dbo.time(table1.col1)) AS ConvertedDate
INTO #TempTable
FROM 
    table1
Leszek Mazur
  • 2,443
  • 1
  • 14
  • 28
0
SELECT CONVERT(smalldatetime, dbo.time(table1.col1)) AS col1
INTO #tableX
FROM table1
ORDER BY col1;
Rodney Ellis
  • 727
  • 2
  • 13
  • 28
  • thanks. will a temp table slower the performance of the overall query? – new_user Jun 02 '20 at 04:43
  • ORDER BY have no sense in this: [look](https://stackoverflow.com/questions/14424929/preserving-order-by-in-select-into) – Leszek Mazur Jun 02 '20 at 04:43
  • when I ran the suggested answer for the first time, it ran. But when i tried to re-run, it says, "There is an already an object named '#tablex' in the database I am in need of a solution that I can re-use. Is there an another way of doing it other than the temp table? – new_user Jun 02 '20 at 04:55
  • 1
    can you elaborate more on why you want it stored in a temp table? (which is what you wrote in the OP). of course you'll get that error if you run it again in the same scope, unless you run a IF EXISTS() ... DROP ... before it. (you can google for examples) – Rodney Ellis Jun 02 '20 at 05:35
  • 1
    @RodneyEllis while I created the OP i didnt realize that this error would occur. I have now edited it. Thanks. Will use the If condition while running in the same schema – new_user Jun 02 '20 at 06:07
  • @new_user - don't forget to mark this as the answer to close the question. :-) – Rodney Ellis Jun 03 '20 at 22:36