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 2000 Forums
 SQL Server Administration (2000)
 inserting a record

Author  Topic 

sanjeevmalai@hotmail.com
Starting Member

4 Posts

Posted - 2005-08-10 : 02:05:03
sir,
i want to insert record into the table for ex....
table name=>mycomp
values of field
field1=>cdrive
field2=> file1,file2......filen
field3=> file

here 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 this
regards
sanjeev

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 entered
Otherwise give more details
Post some sample data

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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'
END
ELSE
BEGIN
INSERT INTO mycomp
(
field1, field2, field3
)
VALUES
(
'cdrive',
'file1,file2......filen',
'file'
)
END

Kristen
Go to Top of Page

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....
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-10 : 09:13:01
Did you follow the method that Kristen suggested?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -