| Author |
Topic |
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-07-29 : 09:13:33
|
| hi iam having tables emrappointmentdetails and emrappointmentdetailshistory tablesthere bill_number one column is there.now iam having one more table emrtpbilleditems where appointment_ids one column is there which is having values like 806658,806659,806660now i have to update this column into above two tables with comma seperated .how can i do please give me the migrate query for this |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-29 : 09:17:33
|
1. how is the 3 tables related ?2. Which table / column do you want to update the appointment_ids to ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
ddramireddy
Yak Posting Veteran
81 Posts |
Posted - 2009-07-29 : 09:19:47
|
| I think this is the query you needed,Update emrappointmentdetails Set bill_number = B.bill_number from emrappointmentdetails A inner join emrtpbilleditems Bon A.ColumnName = B.ColumnNameUpdate emrappointmentdetailshistory Set bill_number = B.bill_number from emrappointmentdetailshistory A inner join emrtpbilleditems Bon A.ColumnName = B.ColumnName |
 |
|
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-07-29 : 09:20:55
|
| 1)both emrappointmentdetails and emrappointmentdetailshistory tables are identical2)table emrtpbilleditems where appointment_ids one column is there which is having values like 806658,806659,8066603)we have to update the from emrtpbilleditems table as comma seperated values for the above two tables bill_number is the column name based on the below table colukm |
 |
|
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-07-29 : 09:24:48
|
| same thing for oracle tooUpdate emrappointmentdetailsSet bill_number = B.bill_numberfrom emrappointmentdetails A inner join emrtpbilleditems Bon A.ColumnName = B.ColumnNameUpdate emrappointmentdetailshistorySet bill_number = B.bill_numberfrom emrappointmentdetailshistory A inner join emrtpbilleditems Bon A.ColumnName = B.ColumnName |
 |
|
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-07-29 : 09:34:53
|
| Update emrappointmentdetailsSet bill_number = B.bill_numberfrom emrappointmentdetails A inner join emrtpbilleditems Bon A.ColumnName = B.ColumnNamehow to write this in oracle |
 |
|
|
ddramireddy
Yak Posting Veteran
81 Posts |
Posted - 2009-07-29 : 09:46:29
|
| try this although I don't oracle.Update emrappointmentdetails set bill_number = ( select bill_number from emrtpbilleditems where A.ColumnName = emrappointmentdetails.ColumnName ) |
 |
|
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-07-29 : 09:47:25
|
| hi can anyone send the oracle query too |
 |
|
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-07-29 : 09:53:58
|
| HI iam getting exception can ypu please send a proper one |
 |
|
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-07-29 : 10:13:45
|
| hi your query is working fine but i dont want commas to be included it shoud be comma seperated |
 |
|
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-07-29 : 10:19:03
|
| how to update comma incuded values to be comma seperated into other table in mssql |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-07-29 : 11:32:40
|
| Can you clearly explain with some sample data for the 3 tables and the expected output. |
 |
|
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-07-29 : 12:11:42
|
| hi,iam having two tablesa)emrappointmentdetails b)emrtpbilleditemsemrtpbilleditemsbillnum ap_ids ap_id--columnsTNOO 80150,80152 12TN11 80152,80156,80159 11emrappointmentdetailsap_id billnum ---columns80150 TNOO80152 TNOO80152 TN1180156 TN1180159 TN11BOTH TABLES ARE HAVING COMMON ap_id as commonnow i have to migrate the script like this,can anyone help me out in this to update emrtpbilleditems to emrappointmentdetailas as the above ones |
 |
|
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-07-29 : 12:41:36
|
| hi can anyone provide any example in such scenarios.so that it will be helpful to me |
 |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2009-07-29 : 13:28:32
|
| Can you show us what your expected results are?Some days you're the dog, and some days you're the fire hydrant. |
 |
|
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-07-29 : 22:25:07
|
| i have mentioned in the above one knowlike emrtpbilleitemsbillnum ap_idsTN00 80150,80152SHOULD BE UPDATED FORemrappointmentdetailsap_id billnum80150 TN0080152 TN00 |
 |
|
|
ddramireddy
Yak Posting Veteran
81 Posts |
Posted - 2009-07-30 : 01:14:59
|
| Hi Rajasekhar, declare @emrtpbilleditems table( billnum varchar(100), ap_ids varchar(100), ap_id int)insert into @emrtpbilleditemsselect 'TNOO','80150,80152',12 union allselect 'TN11', '80152,80156,80159', 11insert into emrappointmentdetailsselect billnum,cValue from @emrtpbilleditems ecross apply fn_split(e.ap_ids,',')here i used fn_Split function, u can get it from here.http://www.umachandar.com/technical/SQL2000Scripts/UtilityFns/Main7.htmBut my advice is pls try to ask this question in oracle forums instead of sql forums. |
 |
|
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-07-30 : 02:42:59
|
| hi i have written a function like thisdrop function GetAPPidsGOCREATE FUNCTION dbo.GetAPPids (@bill_no int,@str varchar(4000)) RETURNS @appids TABLE(bill_number int, appointment_id int)BEGIN DECLARE @appid int, @delimeter int, @beginid int, @cnt int SET @cnt = 1 SET @beginid=1 SET @delimeter = CHARINDEX(',', @str, @cnt) WHILE @delimeter>0 BEGIN SET @appid = substring(@str,@beginid,@delimeter-1) INSERT INTO @appids values(@bill_no, cast(@appid as int)) SET @delimeter = CHARINDEX(',', @str, @beginid) SET @beginid = @delimeter+1 END RETURNENDGOinsert into emrappointmentdetails_bak1 values(bill_number,appointment_id)Select bill_number,appointment_id from dbo.GetAppids(123,'8010840,8010841,8010842')but iam facing exception with insert statement.how can i insert into the table |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-07-30 : 03:10:03
|
| [code]DECLARE @emrtpbilleditems table(billnum varchar(100),ap_ids varchar(100),ap_id int)INSERT INTO @emrtpbilleditemsSELECT 'TNOO','80150,80152',12 union allSELECT 'TN11', '80152,80156,80159', 11SELECT * FROM @emrtpbilleditemsDECLARE @finaltable TABLE (billnum VARCHAR(100),ap_ids INT)INSERT INTO @finaltableSELECT billnum,replace(SUBSTRING(ap_ids,charindex(',',ap_ids,v.number),abs(charindex(',',ap_ids,charindex(',',ap_ids,v.number)+1)-charindex(',',ap_ids,v.number))),',','')as valueFROM @emrtpbilleditems eINNER JOIN master..spt_values AS v ON v.Type = 'P' AND v.number > 0 AND v.number <= len(ap_ids) AND substring(',' + ap_ids, v.number, 1) = ','SELECT * FROM @finaltable[/code] |
 |
|
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-07-30 : 04:22:27
|
| hi how can i use with my function which i have writtenusing this insert statementinsert into emrappointmentdetails_bak1 values(bill_number,appointment_id)Select bill_number,appointment_id from dbo.GetAppids(123,'8010840,8010841,8010842') |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-07-30 : 06:31:48
|
| insert into emrappointmentdetails_bak1(bill_number,appointment_id)Select bill_number,appointment_id from dbo.GetAppids(123,'8010840,8010841,8010842') |
 |
|
|
Next Page
|