• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 422
  • Last Modified:

SQL Server Select Into for SQL Guru

When I try to run this simple statement (below) I get an error -

Msg 102, Level 15, State 1, Line 4
Incorrect syntax near ')'.

If I run the second select by iytself it works -  Any idea why this would occur -
if i can not use row number to number the items in each set within this larger set how can I accomplish this?  
select id , evtdate, userGuid, Interval, FieldName, value, 
point into #temp2 from (Select id , evtdate, userGuid, Interval, FieldName, value, 
ROW_NUMBER() OVER(Partition By ID  Order By FieldName) from #temp)

Open in new window

0
DylanJones1
Asked:
DylanJones1
  • 2
  • 2
1 Solution
 
chapmandewCommented:
very close

select id , evtdate, userGuid, Interval, FieldName, value,
point into #temp2 from (Select id , evtdate, userGuid, Interval, FieldName, value,
ROW_NUMBER() OVER(Partition By ID  Order By FieldName) from #temp)a
0
 
chapmandewCommented:
btw..whenever you do a subquery like that, you have to give it an alias...in the above, i just put an a afterwards....other than that, looks good.
0
 
Patrick MatthewsCommented:
Hello DylanJones1,

You could try this:

select id , evtdate, userGuid, Interval, FieldName, value, IDENTITY(int, 1, 1) AS point
into #temp2
from #temp
order by ID, FieldName

Regards,

Patrick
0
 
Patrick MatthewsCommented:
slow fingers :)
0
 
DylanJones1Author Commented:
Thanks,  I like slow finders suggestion also  just to avoid the row numbering - did we lose the ability to split points?
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now