Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2005
    Posts
    119

    Unanswered: Insert/Select Statement - How to insert/select incrementing value (bulk insert)

    my script is inside a stored procedure. i will create a view that will hold the data from my select query. how can i insert an incrementing value to the view(result set)?

    here's my syntax to further explain...

    CREATE VIEW <ViewName>
    AS
    SELECT <IncrementingValue>, * FROM TableName
    the view created should have an added column containg the incrementing value. how is this? thanks in advance.

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You're creating a view within a stored procedure?! I hope not.

    You have a couple of options - you can use table variables, temporary tables, or windowed functions (SQL 2005+ only for windows functions!).
    George
    Home | Blog

  3. #3
    Join Date
    Dec 2008
    Posts
    135
    but u can't do in creating a view in sp as gerorge said
    try like this in ur sp

    select identity(int,1,1)as id,* into newtablename from urtable
    select * from newtablename

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by bklr
    select identity(int,1,1)as id,* into newtablename from urtable
    select * from newtablename
    Use of analytical functions will trump that in SQL 2005 +. For 2K, it might be the best method.

    Of course, the standard question: what are you displaying the result in? (ASP.NET, Access, Crystal Reports etc)?
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •