Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2006
    Posts
    55

    Unanswered: insert identity id

    hi all,

    i have a question:
    i have a table that has an identity id column called pId and also a column called ParentPid.
    now my question is that i want to insert the value of pId into the ParentPid when i'm adding a new Property to a table.
    any idea?
    thanks
    Peace out
    Mr joka

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Hi

    Check out after update\ insert triggers in BoL. That should cover it for you. You could otherwise use scope_identity but you would need this in your application code.

    HTH
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Oct 2006
    Posts
    55
    thanks for your quick answer, i'm new to sql queries, can you plaese give me an example?
    thanks
    Peace out
    Mr joka

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Sure:
    http://msdn2.microsoft.com/en-us/lib...4(SQL.80).aspx

    Triggers are not an introductory concept.

    One thing has struck me - why do you want to do this? You are just putting the same value into one row in two different fields? How does this help you?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  5. #5
    Join Date
    Oct 2006
    Posts
    55
    thanks,
    i have properties and subproperties i need to select properties and under that put subproperties and this is i'm doing it with the check of ParentPId = PId and i have also the Plevel, if Plevel = 1 then it is category and if Plevel = 2 then it is subcategory.

    i will take a look at the link you send me
    Peace out
    Mr joka

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    how can a row be the parent of itself?

    perhaps what you want is to set the parentid to NULL instead -- this is the "best practice" when a row has no parent, which is what i think you're trying to do here, yes?

    see Categories and Subcategories

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Oct 2006
    Posts
    55
    thanks
    first of all i'm working with prperties: so i have a datalist that shows all the properties, in these properties i have Property and i have subproperties and i'm distinguishing between them with a colunm in my table called level, so if a property has level = 1 then it is a property, if level = 2 then it is subproperty. now when i want to show the properties and subproperties i'm querying my table as that:
    select * from property where level = 2 and parentPId = PropertyId so i wll show just the subproperties of a specific property.
    now the PropertyId is an identity so the id is generating automatically, now what i want is a way so i can insert this propertyid into the ParentPId?

    thanks
    Peace out
    Mr joka

Posting Permissions

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