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.
| Author |
Topic |
|
deep2006
Starting Member
3 Posts |
Posted - 2006-08-23 : 12:58:23
|
| I have two fields CourseID and Erpid in table.CourseID has identity property with integer datatype.I need to add a default value for Erpid column which will show a value like 'A' + CourseID column. Erpid is Varchar column.How can I use Convert function in default constraint?Thanks! |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-08-23 : 13:06:24
|
| If you want a default then probably a trigger is easiest.If you want it to keep that value then a computed column - or don't persist the value.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
deep2006
Starting Member
3 Posts |
Posted - 2006-08-23 : 13:59:49
|
| Thanks for the reply.I am getting a syntax error in the following code.What will be a correct syntax?Thanks again.-----------------------------------------------------create trigger trig_insert on dbo.J_Course for insert as beginDeclare @erpid varchar(40)set @erpid = select 'A' + convert (varchar(50) , CourseID) from dbo.J_Course, inserted where J_Course.Course_ID = inserted.Course_IDupdate dbo.J_Courseset Erpid = @erpid from dbo.J_Course, inserted where J_Course.Course_ID = inserted. Course_IDEnd |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-24 : 02:33:38
|
There were so many errors in the code and logic above, so I took the liberty to rewrite the whole shebang, instead of explaining. There are other people than me who are better in that.create trigger trig_insert on dbo.J_Course for insert as beginUPDATE jSET j.Erpid = 'A' + j.Course_IDFROM dbo.J_Course jINNER JOIN inserted ON i.Course_ID = j.Course_IDEnd Peter LarssonHelsingborg, Sweden |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-08-26 : 03:59:00
|
| Why do you want to have seperate column?In your select statement, cant you use Select 'A'+cast(Course_ID as varchar(10)) from yourTable?MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|