SELECT PID,MAX(SQ) AS 'MaxSQ' FROM BY PID SELECT PID,CD,ROW_NUMBER() OVER (PARTITION BY PID ORDER BY PID) AS 'RowNumber' FROM p1 INSERT INTO p1.PID,p1.CD,p1.RowNumber+ISNULL(p2.MaxSQ,0) FROM If so, please refer to the following sample: DECLARE Table When inserting a new record into table PGM, I think you want:ġ) If no record with the same PID exists in table PGM, the inserted SQ will be 1.Ģ) If there are records with the same PID exist in table PGM, the inserted SQL will be: SELECT MAX(SQ) +1 FROM PGM WHERE PID = Inserting_PID
![serial para max recorder serial para max recorder](https://www.tipucrack.com/wp-content/uploads/2017/03/sadasd.jpg)
What I need to do is insert a record into the PGM table where there is no related record in the STU table AND insert a record into the PGM table where there is a related record(s).Ĭould you please elaborate a bit on this line and show us a sample with your expected result? Is it possible to INSERT a record INTO the PGM table when a STU record PID already exists in the PGM table by getting the MAX SQ related to that PID and incrementing the value by one during the INSERT INTO? Valid expressions are constants, constant expressions, and (in some contexts) variables. The name "SQ" is not permitted in this context. However, because a record can be added with a duplicate PID record IF the SQ fieed associated with the PID is incremented by 1, I attempted to create my insert query like: Cannot insert duplicate key in object 'dbo.PGM'. Violation of PRIMARY KEY constraint 'PrimaryKey_PGM'.
![serial para max recorder serial para max recorder](https://i.ytimg.com/vi/3OcYEsiyEPc/maxresdefault.jpg)
Of course, executing the following INSERT INTO fails: The PGM table allows for duplicate PID records so long as the SQ field has a UNIQUE value specifially an incremented value STU has a one to many relationship with PGM using PID SQ, int = Foriegn Key Field Must increment on INSERT INTO