Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
sir,i want to insert record into the table for ex....table name=>mycompvalues of fieldfield1=>cdrivefield2=> file1,file2......filenfield3=> filehere in my example only field2 value is changing other field1,field3 is a constant one. i want to write one function r procedure to insert the record into the DB by giving only changing field1 value. other field value should get the value from the previous record in the table.see if i want to enter a new record into the table, my job is to give only changing field value, others field values we are get from the previous record stored in the table.how to write procedure for thisregardssanjeev
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2005-08-10 : 02:21:50
>>here in my example only field2 value is changing other field1,field3 is a constant one.Did you set them some default values?If so they will be automatically inserted whenever new record is enteredOtherwise give more detailsPost some sample dataMadhivananFailing to plan is Planning to fail
Kristen
Test
22859 Posts
Posted - 2005-08-10 : 02:24:35
Hi sanjeev, Welcome to SQL Team!Something like this perhaps?
IF EXIST (SELECT * FROM mycomp WHERE field1='cdrive' AND field3='file')BEGIN UPDATE U SET field2 = 'file1,file2......filen' FROM mycomp U WHERE field1='cdrive' AND field3='file'ENDELSEBEGIN INSERT INTO mycomp ( field1, field2, field3 ) VALUES ( 'cdrive', 'file1,file2......filen', 'file' )END
Kristen
sanjeevmalai@hotmail.com
Starting Member
4 Posts
Posted - 2005-08-10 : 09:06:16
c sir, i hav given u an example with 3 field, actually im working on nearly 12 fields. in this i hav to change only one field, oth field are same. for tht i hav to write procedure for this to get value for the constant field from the previous record and for other changing field i hav to giv an input....
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2005-08-10 : 09:13:01
Did you follow the method that Kristen suggested?MadhivananFailing to plan is Planning to fail