Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Best Way To Do This

Author  Topic 

ann
Posting Yak Master

220 Posts

Posted - 2009-07-25 : 16:12:22
I have a sp (inserting new record) whereby one of the fields is ContactNumber made up of the Month,Year & RecordID(Table Record, field RecordID) - so when a new reocrd is created we end up with something like this (assuming todays date and record ID 10) 250910.

Currently in my app., I add my new record, use the returned ID (Scope_ Identity), create the contactNumber using the requirements outlined above, and update the record.

I am trying to figure out how to do this all within the inserting of the new record, but keep running into problems - can anyone help on this?

Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-26 : 00:28:40
Use the new OUTPUT operator.
See how here http://weblogs.sqlteam.com/peterl/archive/2007/10/03/New-OUTPUT-operator.aspx



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2009-07-26 : 13:12:55
There's a month "25"???

--Jeff Moden
"Your lack of planning DOES constitute an emergency on my part... SO PLAN BETTER! "
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row"

Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2009-07-26 : 13:16:11
quote:
ContactNumber made up of the Month,Year & RecordID(Table Record, field RecordID) - so when a new reocrd is created we end up with something like this (assuming todays date and record ID 10) 250910.


Actually, that's a pretty bad way to do things... it denormalizes the column by having two types of data (date/time and sequence) in the same table and it's just the wrong way to do things as you're finding out right now. It'll be a PITA for the rest of the life of the program, to boot.

Can't you just use an IDENTITY column?

--Jeff Moden
"Your lack of planning DOES constitute an emergency on my part... SO PLAN BETTER! "
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row"

Go to Top of Page
   

- Advertisement -