Showing posts with label write. Show all posts
Showing posts with label write. Show all posts

Thursday, March 22, 2012

Do for each - how to write it more graceful?

"Do something for each row of the query"
The only way I know is:

--
declare @.C cursor
set @.C= cursor for
select F from T where ...
declare @.F int
open @.C
while 0=0 begin
fetch next from @.C into @.F
if not(@.@.FETCH_STATUS = 0) break
exec myStoredProc @.F
end
close @.C
deallocate @.C
--

How to write it simpler, maybe with implicit cursors?
For example, in the Borland Interbase it would be like:

--
declare variable F integer;
for select F from T into :F
do execute procedure myStoredProc :F;
--

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!What does myStoredProc actually do? If the procedure just does some data
manipulation then maybe you can rewrite that code based on your cursor
query. For example:

SELECT ...
FROM Something
WHERE f
IN
(select F from T where ...)

As another alternative to a cursor you can try something like this, which
may be reasonably acceptable if the column F is unique and indexed.

DECLARE @.f INTEGER

WHILE EXISTS
(SELECT *
FROM T
WHERE f>@.f
OR @.f IS NULL)
BEGIN
SET @.f =
(SELECT MIN(f)
FROM T
WHERE f>@.f
OR @.f IS NULL)
EXEC myStoredProc @.F
END

--
David Portas
SQL Server MVP
--|||Thank you for these two ideas!
But... first case is not quite fit for me. My stored procedure is too
complicated, it makes some queries to remote server, calls some extended
procedures and so on.
Second case seems better, but (IMHO) it's a trick. And this trick (IMHO)
is too slow relative to case with cursor and fetch. And it looks like
T-SQL syntax limitation - no any common and short way to do something
for each row, like cycle by select :(

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||Other options:

1) Build a Dynamic SQL statement in a loop and then execute it.

2) Put the loop in the middle tier or client code.

3) For non-production use you could try the undocumented xp_execresultset.
Example:

EXEC master..xp_execresultset
'SELECT ''EXEC myStoredProc ''+CAST(f AS VARCHAR) FROM T','DBNAME'

--
David Portas
SQL Server MVP
--|||Evgeny Gopengauz (evgop@.ucs.ru) writes:
> "Do something for each row of the query"
> The only way I know is:
> --
> declare @.C cursor
> set @.C= cursor for
> select F from T where ...
> declare @.F int
> open @.C
> while 0=0 begin
> fetch next from @.C into @.F
> if not(@.@.FETCH_STATUS = 0) break
> exec myStoredProc @.F
> end
> close @.C
> deallocate @.C
> --
> How to write it simpler, maybe with implicit cursors?

There are a couple of options, you can use SELECT MIN or SELECT TOP 1.
I would however recommend to stick with the cursors, they are in my
opinion the best way to iterate when you need to iterate. Solutions
with MIN or TOP 1 can have bad performance if there is no good index.

One tip is to make the cursor INSENSITIVE, since keyset-driven cursors
(the default) can sometimes have absymal performance when nailing
down which rows to operate on. Also insensitive saves you from
surprises if you update rows selected by the cursor.

Finally, I never use cursor variables, but always static names.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.aspsql

Wednesday, March 21, 2012

DMX Query for regression coefficients

How do I write a DMX query to return the coefficients of the independent variables in my regression equation?

Thanks,

Carrie

All algorithm content is in the content schema rowset available through

SELECT * FROM <model name>.CONTENT

Although the schema is the same for all algorithms, each uses the schema slightly differently. The schema itself is difficult to decode, but you can download a plug-in viewer from http://www.sqlserverdatamining.com/dmcommunity/_downloads/1348.aspx that decodes all the types/etc into their parts. Once you do this, you will see what columns/etc you need from the content.

|||

We do not have the sgKey.snk file. Can we generate one? If so how?

Cryptographic failure while signing assembly 'C:\Documents and Settings\dtm\My Documents\dot net examples\Generic Content Viewer\GenericContentTreeViewerSetup\obj\Debug\GenericContentTreeView.dll' -- 'Error reading key file 'c:\Documents and Settings\dtm\My Documents\dot net examples\Generic Content Viewer\GenericContentTreeViewerSetup\sgKey.snk' -- The system cannot find the file specified. '

Thanks

|||Something happened to the download - the snk file isn't the only one missing - we're looking into it. However, the setup should have installed the viewer anyway, so you should see it in BI Dev Studio, did it not?|||

I understand the content viewer now. I thought maybe I was looking for something different but now I see.

Three more questions:

1. My regressor variable has three values associated with it. I understand the first (the coefficient in the regression equation) and the third, used to calculate the constant - but what is the second value? A screenshot would probably be more helpful.

2. How do I set an input variable to regressor in the mining wizard. It is not listed as a modeling flag option. If I have more than one regressor - will both regressors be included as part of the regression equation?

3. In my regression trees, if a node does not have a regression equation associated with it, is the model overtrained? How do I interpret these results?

Thanks so much,

Carrie

|||

1: I don't have it in front of me right now, so a screenshot would help :)

2: When you create a decision tree with continuous inputs and outputs, I believe the wizard automatically marks all continuous values as REGRESSOR. You can verify this by going to the Mining Models pane in the Data Mining designer. Click on a column name under the mining model (not the mining structure) and look at its properties in the property panel. This is where you can set algorithm-specific modeling flags, and where you would set or clear the REGRESSOR flag.

3. I wouldn't say it was necessarily overtrained, just that there were no significant regressors for that node. For example, assume I had a bunch of demographic data including Age and IQ as my only continuous values and I tried to predict either one. Statistically speaking, they should be independent and there shouldn't be any regressions - just constants. That being said, and since it may not be the case for your model, there are a couple of options open to you. If you think the model may be overfitting, you can increase the MINIMUM_SUPPORT parameter, or the COMPLEXITY_PENALTY parameter. Both of these have the impact of reducing the size of your tree. Additionally, the decision tree algorithm has a FORCE_REGRESSOR parameter allowing you to specify a regressor that will be included in any regression, regardless of how minimal its contribution

|||Is there a dmx query that will return the actual numeric value of the diamond (residual) in each node of the regression tree?|||I am just making sure my question is still in the cue....thanks|||

Assuming your model name was "cp" and your attribute name was "IQ", I think this is the query you want

select FLATTENED NODE_CAPTION,
NODE_NAME,
(select ATTRIBUTE_VALUE AS mean,
[VARIANCE] as [variance]
from NODE_DISTRIBUTION WHERE VALUETYPE=3)
as stats
from cp.content WHERE ATTRIBUTE_NAME='IQ'

DMX Query for regression coefficients

How do I write a DMX query to return the coefficients of the independent variables in my regression equation?

Thanks,

Carrie

All algorithm content is in the content schema rowset available through

SELECT * FROM <model name>.CONTENT

Although the schema is the same for all algorithms, each uses the schema slightly differently. The schema itself is difficult to decode, but you can download a plug-in viewer from http://www.sqlserverdatamining.com/dmcommunity/_downloads/1348.aspx that decodes all the types/etc into their parts. Once you do this, you will see what columns/etc you need from the content.

|||

We do not have the sgKey.snk file. Can we generate one? If so how?

Cryptographic failure while signing assembly 'C:\Documents and Settings\dtm\My Documents\dot net examples\Generic Content Viewer\GenericContentTreeViewerSetup\obj\Debug\GenericContentTreeView.dll' -- 'Error reading key file 'c:\Documents and Settings\dtm\My Documents\dot net examples\Generic Content Viewer\GenericContentTreeViewerSetup\sgKey.snk' -- The system cannot find the file specified. '

Thanks

|||Something happened to the download - the snk file isn't the only one missing - we're looking into it. However, the setup should have installed the viewer anyway, so you should see it in BI Dev Studio, did it not?|||

I understand the content viewer now. I thought maybe I was looking for something different but now I see.

Three more questions:

1. My regressor variable has three values associated with it. I understand the first (the coefficient in the regression equation) and the third, used to calculate the constant - but what is the second value? A screenshot would probably be more helpful.

2. How do I set an input variable to regressor in the mining wizard. It is not listed as a modeling flag option. If I have more than one regressor - will both regressors be included as part of the regression equation?

3. In my regression trees, if a node does not have a regression equation associated with it, is the model overtrained? How do I interpret these results?

Thanks so much,

Carrie

|||

1: I don't have it in front of me right now, so a screenshot would help :)

2: When you create a decision tree with continuous inputs and outputs, I believe the wizard automatically marks all continuous values as REGRESSOR. You can verify this by going to the Mining Models pane in the Data Mining designer. Click on a column name under the mining model (not the mining structure) and look at its properties in the property panel. This is where you can set algorithm-specific modeling flags, and where you would set or clear the REGRESSOR flag.

3. I wouldn't say it was necessarily overtrained, just that there were no significant regressors for that node. For example, assume I had a bunch of demographic data including Age and IQ as my only continuous values and I tried to predict either one. Statistically speaking, they should be independent and there shouldn't be any regressions - just constants. That being said, and since it may not be the case for your model, there are a couple of options open to you. If you think the model may be overfitting, you can increase the MINIMUM_SUPPORT parameter, or the COMPLEXITY_PENALTY parameter. Both of these have the impact of reducing the size of your tree. Additionally, the decision tree algorithm has a FORCE_REGRESSOR parameter allowing you to specify a regressor that will be included in any regression, regardless of how minimal its contribution

|||Is there a dmx query that will return the actual numeric value of the diamond (residual) in each node of the regression tree?|||I am just making sure my question is still in the cue....thanks|||

Assuming your model name was "cp" and your attribute name was "IQ", I think this is the query you want

select FLATTENED NODE_CAPTION,
NODE_NAME,
(select ATTRIBUTE_VALUE AS mean,
[VARIANCE] as [variance]
from NODE_DISTRIBUTION WHERE VALUETYPE=3)
as stats
from cp.content WHERE ATTRIBUTE_NAME='IQ'

DMX Query examples

Can you give an example on how exactly to write each of the following? (I am clearly not a programmer :))

TopCount ( <table expr>,<rank expr>,<n-items>) =

TopPercent ( <table expr>,<rank expr>,<percent>) =

PredictTimeSeries ( <table expr>,<n1>,<n2>) =

PredictAssociation ( <table expr>,<n>) =

Thanks,

Carrie

SELECT TopCount(PredictHistogram(MyAttribute),$Probability,3), // returns top 3 values by probability
TopPercent(PredictHistogram(MyAttribute),$Support,0.20) // returns top values that contain at least 20% of the total support
FROM MyModel
PREDICTION JOIN
...

SELECT PredictTimeSeries(MyNestedTableTimeSeriesColumn, 2, 5) // predicts steps 2-5 in the series
FROM MyTimeSeriesModel

SELECT PredictAssociation(MyNestedTable, 5) // returns top 5 associated items
FROM My Model
PREDICTION JOIN
...

|||

So I did.....

select TopCount(PredictHistogram(Returnwithplay),$Support,.20)

From [REC FT All Cube DT]

PREDICTION JOIN

And received the following ( I think the query completed with errors):

Executing the query ...

Parser: The end of the input was reached.

Execution complete

|||And I tried

select PredictTimeSeries([Slot Theo Win],2,5) FROM [Player Market]

and received the following error:

Executing the query ...

Error (Data mining): The specified DMX column was not found in the context at line 1, column 26.

Execution complete

My time series is set up as the following.......

Player Market:

Date Dim Predict

Day Key

Rated Slot Theo Predict Only

Rated Table Theo Predict Only

Player Market Dim Key

|||

PredictTimeSeries only works on models using the Microsoft_Time_Series algorithm. Also, it doesn't seem that you have a column called "Slot Theo Win" in your data set.

It seems you would need a model somewhat like

CREATE MINING MODEL [Player Market]
(
DateDim DATE KEY TIME,
PlayerMarketDim TEXT KEY,
RatedSlotTheo DOUBLE CONTINUOUS PREDICT_ONLY,
RatedSlotTheo DOUBLE CONTINUOUS PREDICT_ONLY
) USING Microsoft_Time_Series

sql

Sunday, March 11, 2012

dll locked by VS

Hi,
I'm new to VS-Development an have to write a little assembly for Reporting
Services. Every time a change something in the assembly, I call the
following .bat-file:
copy "D:\rw\Visual Studio
2005\wbiReports\wbiReports\bin\Debug\wbiReports.dll" "C:\Programme\Microsoft
SQL Server\MSSQL.3\Reporting Services\ReportServer\bin\"
copy "D:\rw\Visual Studio
2005\wbiReports\wbiReports\bin\Debug\wbiReports.dll" "\\wbi-lyta\C$\Program
Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\bin\"
copy "D:\rw\Visual Studio
2005\wbiReports\wbiReports\bin\Debug\wbiReports.dll" "C:\Programme\Microsoft
Visual Studio 8\Common7\IDE\PrivateAssemblies\"
But the last copy fails, if there is still one VS open. I normally have 3
projects open, 2 reports and the assembly-project. Now having to close not
only every project but even close all VSs is very annoying. Am I doing
anything wrong?
Regards,
RalphI have run into the same problem. The best workaround I found is to
use NUnit to do all of my testing for the assembly. When I'm done I
install it into the appropriate directories and modify and test my
reports. This allows me to avoid the problem for the most part.

Friday, March 9, 2012

Divide by zero display "0"

Hello,
how would I write an if statement to ensure that a "0" is displayed if a
divide 0/0?
Thanksiif(<field.total>=0,0,<field.numerator>/(<field.total>)
U. Tokklas
"Fab" wrote:
> Hello,
> how would I write an if statement to ensure that a "0" is displayed if a
> divide 0/0?
> Thanks
>
>|||Note: IIF is a function call. All arguments get evaluated before invoking
the function. Therefore, a DivisionByZero can still happen.
Use the following pattern:
=iif( Fields!Total.Value = 0, 0, Fields!X.Value / iif(Fields!Total.Value=0,
1, Fields!X.Value))
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"Tokklas" <Tokklas@.discussions.microsoft.com> wrote in message
news:7381410F-FE63-4DAA-9D8D-3F426D24CCD8@.microsoft.com...
> iif(<field.total>=0,0,<field.numerator>/(<field.total>)
> U. Tokklas
>
> "Fab" wrote:
>> Hello,
>> how would I write an if statement to ensure that a "0" is displayed if a
>> divide 0/0?
>> Thanks
>>
>>

Saturday, February 25, 2012

Distribution licensing

Hi
If I write app with a sql server as backend, what are the licensing
requirements for distribution of the app sql server wise i.e. does the
client need to buy their on sql server ort can I distribute parts of it as
part of my app? I need to use Merge Replication so I doubt I can distribute
the app with sql server express.
Thanks
Regards
If you use SQL Server Express or MSDE you do not need to have licenses on
the subscribers, but you will need to license the publisher for every
connection made to it. So if you have 300 subscribers you will need 300
Calls.
http://www.zetainteractive.com - Shift Happens!
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"John" <John@.nospam.infovis.co.uk> wrote in message
news:%23GIlwXpKIHA.4752@.TK2MSFTNGP05.phx.gbl...
> Hi
> If I write app with a sql server as backend, what are the licensing
> requirements for distribution of the app sql server wise i.e. does the
> client need to buy their on sql server ort can I distribute parts of it as
> part of my app? I need to use Merge Replication so I doubt I can
> distribute the app with sql server express.
> Thanks
> Regards
>
>
>
>

Distribution licensing

Hi
If I write app with a sql server as backend, what are the licensing
requirements for distribution of the app sql server wise i.e. does the
client need to buy their on sql server ort can I distribute parts of it as
part of my app? I need to use Merge Replication so I doubt I can distribute
the app with sql server express.
Thanks
RegardsIf you use SQL Server Express or MSDE you do not need to have licenses on
the subscribers, but you will need to license the publisher for every
connection made to it. So if you have 300 subscribers you will need 300
Calls.
--
http://www.zetainteractive.com - Shift Happens!
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"John" <John@.nospam.infovis.co.uk> wrote in message
news:%23GIlwXpKIHA.4752@.TK2MSFTNGP05.phx.gbl...
> Hi
> If I write app with a sql server as backend, what are the licensing
> requirements for distribution of the app sql server wise i.e. does the
> client need to buy their on sql server ort can I distribute parts of it as
> part of my app? I need to use Merge Replication so I doubt I can
> distribute the app with sql server express.
> Thanks
> Regards
>
>
>
>

Distribution licensing

Hi
If I write app with a sql server as backend, what are the licensing
requirements for distribution of the app sql server wise i.e. does the
client need to buy their on sql server ort can I distribute parts of it as
part of my app? I need to use Merge Replication so I doubt I can distribute
the app with sql server express.
Thanks
RegardsIf you use SQL Server Express or MSDE you do not need to have licenses on
the subscribers, but you will need to license the publisher for every
connection made to it. So if you have 300 subscribers you will need 300
Calls.
http://www.zetainteractive.com - Shift Happens!
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"John" <John@.nospam.infovis.co.uk> wrote in message
news:%23GIlwXpKIHA.4752@.TK2MSFTNGP05.phx.gbl...
> Hi
> If I write app with a sql server as backend, what are the licensing
> requirements for distribution of the app sql server wise i.e. does the
> client need to buy their on sql server ort can I distribute parts of it as
> part of my app? I need to use Merge Replication so I doubt I can
> distribute the app with sql server express.
> Thanks
> Regards
>
>
>
>

Distribution licensing

Hi
If I write app with a sql server as backend, what are the licensing
requirements for distribution of the app sql server wise i.e. does the
client need to buy their on sql server ort can I distribute parts of it as
part of my app? I need to use Merge Replication so I doubt I can distribute
the app with sql server express.
Thanks
Regards
If you use SQL Server Express or MSDE you do not need to have licenses on
the subscribers, but you will need to license the publisher for every
connection made to it. So if you have 300 subscribers you will need 300
Calls.
http://www.zetainteractive.com - Shift Happens!
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"John" <John@.nospam.infovis.co.uk> wrote in message
news:%23GIlwXpKIHA.4752@.TK2MSFTNGP05.phx.gbl...
> Hi
> If I write app with a sql server as backend, what are the licensing
> requirements for distribution of the app sql server wise i.e. does the
> client need to buy their on sql server ort can I distribute parts of it as
> part of my app? I need to use Merge Replication so I doubt I can
> distribute the app with sql server express.
> Thanks
> Regards
>
>
>
>