Showing posts with label structure. Show all posts
Showing posts with label structure. Show all posts

Sunday, March 11, 2012

Error in Prediction query

Hi,

I have the following association model Structure

Where I am trying to find out the associations between various service activities so that when a customer buys a service activity we can recommend him/her others

CaseTable

CustomerId à Key

IncidentId

Nested Table

ServiceId à Key

ServiceName à Input, Predict

IncidentId à Link to the case table

Firstly is the above structure correct?

Secondly

I have the following prediction query

SELECT

t.[ServiceId],

Predict ([ServicerossSell].[ServiceCross-SellRecommend],3)

From

[ServicerossSell]

PREDICTIONJOIN

SHAPE

{OPENQUERY([Adventure Works Cycle MSCRM],

'SELECT DISTINCT ServiceId FROM Service ORDER BY ServiceId]')

}

APPEND

( {OPENQUERY([Adventure Works Cycle MSCRM],

'SELECT DISTINCT ServiceId FROM Service ORDER BY ServiceId]')

}

RELATE [ServiceId]To [ServiceId]

)

AS [Service]

AS t

ON

[ServicerossSell].[ ServiceCross-SellRecommend].[ServiceId] = t.[Service].[ServiceId]

It throws the following error

“The DMX column was not found in the context”

I am not able to figure out why, any help would be most appretaiated

The SHAPE clause is wrong - it should be joining the customer/incident table with the incident/service table, not doing a self-join.

Given that your case is a customer with the nested table being the services purchased by them (across multiple incidents), I recommend simplifying the input data as well as the modeling by using a named query in the DSV as follows:

SELECT a.CustomerId, b.ServiceName
FROM CustomerIncident a INNER JOIN IncidentService b
ON a.IncidentId = b.IncidentId
ORDER BY CustomerId

The mining structure can then look like this:

CREATE MINING MODEL CustomerServiceAssociations

(

CustomerId TEXT KEY,

CustomerServices TABLE PREDICT

(

ServiceName TEXT KEY

)

)

USING Microsoft_Association_Rules

|||

Hi Raman,

I took your suggestion and modified the dsv and the mining model as mentioned by you.

And I also modified the prediction query as follows.

SELECT

t.[ServiceId],

PredictAssociation([Association].[Services],3)

From

[Association]

PREDICTIONJOIN

OPENQUERY([Adventure Works Cycle MSCRM],

'SELECT DISTINCT

[ProductId]

FROM

(SELECT ServiceId FROM ServiceBase) as [Service]

')AS t

ON

[Association].[Service Id] = t.[ServiceId]

I am facing a new problem now.

The model is predicting the same set of services for every case. Even changes in the algorithm parameter value do not have any impact on the result.

What is the reason for this and how can u rectify it?

I am facing this problem with other association based mining models also.

Wednesday, February 15, 2012

Error Handling in SQL Server 2000 - Need Help

Hi Everyone:

I have a stored procedure with the following structure and I would like to find out how to catch my error from each block, and raise them if transaction is rolled back in the end. As you can see, I am on SQL Server 2000, so no TRY CATCH functionality is supported, please let me know, specificaly I am looking for the code that would catch the raiserror msgs from each block, and return in the block all the way in the end, where it says if @.@.error condition. Thanks and here is the code:

CREATE PROCEDURE [dbo].[uspSaveLoanApplicationMain]

@.Bor_BorrowerGuid uniqueidentifier,

@.Bor_FirstName varchar(15),

@.Bor_LastName varchar(35),

--and so forth

AS

SET NOCOUNT OFF

BEGIN

BEGIN TRANSACTION

- Block 1 Starts

EXEC sp--

IF @.@.ROWCOUNT = 0

BEGIN

RAISERROR('Save Application Cosigner not updated', 1, 1)

END

Block 1 Ends

-- Similar to block 1 I have block 2,3 and so forth with similar structure, and in the end I -- commit transaction as you can see below.

COMMIT TRANSACTION

RETURN

IF @.@.Error > 0

ROLLBACK TRANSACTION

- Raise an error with the details of the exception

RETURN

END

Thanks.

u can make use of goto....

Create proc

@.a,@.b

AS

block 1

-statements

if @.@.error <>0

goto ErrorBlock

block 1

-statements

if @.@.error <>0

goto ErrorBlock

return 0

ErrrorBlock :

rollback transaction

--raise error a custom message

-- u can keep a table with custom error messages and use them to get the exact error message in goto.... or use the config variables in raiseerror and set correct values for them to form an error statement...

|||

You need to check @.@.ERROR after each block. Because error in block #1 doesn't stop execution of block #2. Also @.@.ERROR save last error id

For example, following code:

sp_addmessage 50001, 16, 'Error1'

sp_addmessage 50002, 16, 'Error1'

begin

RAISERROR (50001,16,1)

end

begin

RAISERROR (50002,16,1)

end

print @.@.ERROR

return

Msg 50001, Level 16, State 1, Line 2

Error1

Msg 50002, Level 16, State 1, Line 5

Error1

50002

Also, if severity level less than 11, then @.@.ERROR==0

|||

So what you are saying is that I can do this in the end and it should work:

IF @.@.Error > 0

ROLLBACK TRANSACTION

PRINT @.@.Error

RETURN

Because I am already doing RAISEERROR if you notice my code block where the sp is called, please clarify/confirm.

BEGIN

EXEC dbo.uspSaveApplicationReference @.CoborRef2

IF @.@.ROWCOUNT = 0

BEGIN

RAISERROR('Save Cosigner Reference 2 not updated', 1, 1)

END

END

Thanks and please let me know.

|||

yes....as whenever an error occurs, we r passing the control to GOTO... so u need to handle it just there...

have a look at this link ... http://www.codeproject.com/database/sqlservertransactions.asp