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 |
scubaculture
Starting Member
2 Posts |
Posted - 2007-02-22 : 08:18:41
|
Hi everyoneI am an asp developer (don't laugh) and have been given a dts taks to modify. The old developer did a step using activex scripts which the powers that be want modified to be a sql task.A client file is imported (got this working fine), these new records then need to go through the old step:Check if each new record exists already.If exists check another table to get a certain flagIf that flag exists check yet another table for 2 valuesIf those 2 values are not null update the temporary table.So in activex script its something likersID.Open sqlID, myConnIf rsTaxID.Eof Then While Not rsID.EofrsID.movenextWendEnd ifCan that be done in an execute sql task?Thanks for any helpI am not sure if this is possible in a sql task? |
|
mwjdavidson
Aged Yak Warrior
735 Posts |
Posted - 2007-02-22 : 11:04:11
|
The powers that be are entirely correct in this instance! This would be far better accomplished in an execute SQL task.It's probably easiest if you post the current ActiveX script in its entirety, so I can give you a T-SQL equivalent.Mark |
|
|
scubaculture
Starting Member
2 Posts |
Posted - 2007-02-22 : 11:23:54
|
Thanks very much for the reply MarkScript:'**********************************************************************' Visual Basic ActiveX Script'************************************************************************' Function explanation:' first get the tax_id where bluecare is y to select all bluecare providers' find the matching providers in the db1a providers table using taxid, if none found insert into exception table and create text file' once provider is matched we need to check the priv_status_history table for the dip_level and priv_status_code, again search on taxid order by sequence' if no dip_level or priv_status_code is found insert into exception table and create text file' client_facilities_update table is then updated to include the dip_level and priv_status_code' check db1a for provider and priv_status_history Function Main()Dim rsTaxIDDim sqlTaxIDDim rsProviderIDDim sqlProviderIDDim dip_levelDim priv_status_codeDim rsDipPrivDim sqlDipPrivDim rsInsertDim sqlInsertDim finaltaxIDdim rsExceptiondim sqlExceptiondim rsExceptionInsertdim sqlExceptionInsertdim rsException2dim sqlException2dim sqlExceptionInsert2dim rsExceptionInsert2Dim masterDim master2Dim fso 'File system objectSet fso = CreateObject("Scripting.FileSystemObject") IF (fso.FileExists("ProfExceptionLog.txt")) THEN Set master = fso.OpenTextFile("ProfExceptionLog.txt",8)master.WriteLine "File Opened @ " & nowmaster.WriteLine "Not found in the provider table:" ELSE Set master = fso.CreateTextFile("ProfExceptionLog.txt")master.WriteLine "File Created @ " & nowmaster.WriteLine "Not found in the provider table:" END IFDim fso2 'File system objectSet fso2 = CreateObject("Scripting.FileSystemObject") IF (fso2.FileExists("ProfHistoryExceptionLog.txt")) THEN Set master2 = fso2.OpenTextFile("ProfHistoryExceptionLog.txt",8)master2.WriteLine "File Opened @ " & nowmaster2.WriteLine "Not found in the priv_status_history table:" ELSE Set master2 = fso.CreateTextFile("ProfHistoryExceptionLog.txt")master2.WriteLine "File Created @ " & nowmaster2.WriteLine "Not found in the priv_status_history table:" END IF'get the tax_id where bluecare is ysqlTaxID = "select tin from prof_temp where ct_bluecare = 'Y'"Set rsTaxID = CreateObject("ADODB.Recordset")rsTaxID.Open sqlTaxID, myConn If rsTaxID.Eof Then'error checking Else While Not rsTaxID.Eof ' find the matching providers using taxid ' from [sac-w2s-db1a].bcbsga.dbo.physicians p sqlProviderID = " select p.provider_tax_id from providers p " & _ " where p.provider_tax_id = '" & rsTaxID("tin") & "' " Set rsProviderID = CreateObject("ADODB.Recordset") rsProviderID.Open sqlProviderID, myConn If rsProviderID.Eof Then'error checkingsqlException = "select provider_id, tin, last_name, first_name, address from prof_temp where tin = '" & rsTaxID("tin") & "' "Set rsException = CreateObject("ADODB.Recordset")rsException.Open sqlException, myConnmaster.WriteLine rsException("provider_id") & "," & rsException("tin") & "," & rsException("last_name") & "," & rsException("first_name") & "," & rsException("address")sqlExceptionInsert = "insert into prof_exception(tin, provider_id, last_name, first_name, dateentered) values ('"& rsException("tin") &"', '"& rsException("provider_id") &"', '"& rsException("last_name") &"', '"& rsException("first_name") &"', getdate())"Set rsExceptionInsert = CreateObject("ADODB.Recordset")rsExceptionInsert.Open sqlExceptionInsert, myConn'update client fac table as nothing can be deleted, these will need to be manually edited by privelligingstrsqlupdate = "update client_facilities_update set dip_level = ' ', priv_status_code = ' ' where provider_tax_id = '"& rsTaxID("tin") &"' " Set rsUpdate = CreateObject("ADODB.Recordset")rsUpdate.Open strsqlupdate, myConn else While Not rsProviderID.Eof 'get the dip and privcode sqlDipPriv = "select top 1 dip_level, priv_status_code from priv_status_history where car_id ='44' and provider_tax_id = '"& rsProviderID("provider_tax_id") &"' order by sequence desc" Set rsDipPriv = CreateObject("ADODB.Recordset") rsDipPriv.Open sqlDipPriv, myConn If rsDipPriv.Eof Then'no provider history found then exception report generatedsqlException2 = "select provider_id, tin, last_name, first_name, address from prof_temp where tin = '" & rsProviderID("provider_tax_id") & "' "Set rsException2 = CreateObject("ADODB.Recordset")rsException2.Open sqlException2, myConnmaster2.WriteLine rsException2("provider_id") & "," & rsException2("tin") & "," & rsException2("last_name") & "," & rsException2("first_name") & "," & rsException2("address")'exceptions also storedsqlExceptionInsert2 = "insert into prof_priv_status_exception(tin, provider_id, last_name, first_name, dateentered) values ('"& rsException2("tin") &"', '"& rsException2("provider_id") &"', '"& rsException2("last_name") &"', '"& rsException2("first_name") &"', getdate())"Set rsExceptionInsert2 = CreateObject("ADODB.Recordset")rsExceptionInsert2.Open sqlExceptionInsert2, myConn'update client fac table as nothing can be deleted, these will need to be manually edited by privelligingstrsqlupdate = "update client_facilities_update set dip_level = ' ', priv_status_code = ' ' where provider_tax_id = '"& rsProviderID("provider_tax_id") &"' " Set rsUpdate = CreateObject("ADODB.Recordset")rsUpdate.Open strsqlupdate, myConn else While Not rsDipPriv.Eof ' this is where you update the client_facilities_update table to include the dip_levelstrsqlupdate = "update client_facilities_update set dip_level = '" & rsDipPriv("dip_level") & "', priv_status_code = '" & rsDipPriv("priv_status_code") & "' where provider_tax_id = '"& rsProviderID("provider_tax_id") &"' " Set rsUpdate = CreateObject("ADODB.Recordset") rsUpdate.Open strsqlupdate, myConn rsDipPriv.movenext Wend end ifrsProviderID.movenextWendEnd ifrsTaxID.movenextWendEnd ifmaster2.WriteLine "file completed at: " & nowset fso = nothingset objfso = nothingset master = nothingset fso2 = nothingset objfso2 = nothingset master2 = nothingMain = DTSTaskExecResult_SuccessEnd Function |
|
|
|
|
|
|
|