Showing posts with label working. Show all posts
Showing posts with label working. Show all posts

Thursday, March 29, 2012

Configure IIS for Reporting Manager and reporting server site

Dear All:

My reporting manager and reporting server were working fine in IIS. But when I booted the system one day, one error message came "Unexpected error" for the IIS. So I removed the IIS and reinstalled he same.

But after that, I tried to give virtual directories to reporting manager and reporting server sites. But it ain't working. Could you please help me?

My IIS 5.1
Reporting service 2005 Express with SQL Server Express
ASP.NET 2.0 Express.

Please help.

Thanks in Advance

Emmanuel MathewDear All:

I got it somehow worked. But now the problem is that when I take the report manager and display the report, it shows me a wrongly formatted page with "Object reference not set to an isntance of an Object"

But in server, even though I am getting the unformatted (Like CSS is not applied), I get the report correctly. Is there anything wrong with the ath of CSS?

And what is this "Object reference error"? Could you please help me.

Thanks
Emmanuel Mathew|||Can you tell us the stack trace in report service log file? Also is there any error in the reporting services configuration tool (not sure if it comes with RS express)?|||Dear Friend:

There is no error screen to take a stack trace. Let me explain. When I give the URL, the reporting manager comes nicely. Then when I click on one of the report, usually, the parameter and the view report button should appear. It appears. But they are all mis aligned. And when Press on the view report, the image which shows the processing rotates and then shows the error in a single line "Object reference not set to an instance of an Object"

When I open the reporting server, I get the directory listing and then when I click on one of the report, the report comes mis aligned as in report manager. But when I click on the view report, it shows the report even though its looking ugly. I get the error only in reporting manager.

Let me tell you what had happened earlier too. One day when I opened the machine, my IIS got an unexpected error and it did not start. SO I reisntalled the same. After reinstalling, I saw that the reporting manager and the server virtual folders are gone. So I created the same and ran the command Reg IIS to register IIS for the ASP.NET 2. I have .NET, sql server and the reporting services which are all express editions installed in the machine. Everything was working fine till I find one day my IIS got corrupted.

Lot of thanks for the support. And thanks in Advance.

Emmanuel Mathew|||I reinstalled IIS and the server stated working fine now. I know its not the solution. But I made it working. Thanks a lot for your help.

Configure IIS for Reporting Manager and reporting server site

Dear All:

My reporting manager and reporting server were working fine in IIS. But when I booted the system one day, one error message came "Unexpected error" for the IIS. So I removed the IIS and reinstalled he same.

But after that, I tried to give virtual directories to reporting manager and reporting server sites. But it ain't working. Could you please help me?

My IIS 5.1
Reporting service 2005 Express with SQL Server Express
ASP.NET 2.0 Express.

Please help.

Thanks in Advance

Emmanuel MathewDear All:

I got it somehow worked. But now the problem is that when I take the report manager and display the report, it shows me a wrongly formatted page with "Object reference not set to an isntance of an Object"

But in server, even though I am getting the unformatted (Like CSS is not applied), I get the report correctly. Is there anything wrong with the ath of CSS?

And what is this "Object reference error"? Could you please help me.

Thanks
Emmanuel Mathew|||Can you tell us the stack trace in report service log file? Also is there any error in the reporting services configuration tool (not sure if it comes with RS express)?|||Dear Friend:

There is no error screen to take a stack trace. Let me explain. When I give the URL, the reporting manager comes nicely. Then when I click on one of the report, usually, the parameter and the view report button should appear. It appears. But they are all mis aligned. And when Press on the view report, the image which shows the processing rotates and then shows the error in a single line "Object reference not set to an instance of an Object"

When I open the reporting server, I get the directory listing and then when I click on one of the report, the report comes mis aligned as in report manager. But when I click on the view report, it shows the report even though its looking ugly. I get the error only in reporting manager.

Let me tell you what had happened earlier too. One day when I opened the machine, my IIS got an unexpected error and it did not start. SO I reisntalled the same. After reinstalling, I saw that the reporting manager and the server virtual folders are gone. So I created the same and ran the command Reg IIS to register IIS for the ASP.NET 2. I have .NET, sql server and the reporting services which are all express editions installed in the machine. Everything was working fine till I find one day my IIS got corrupted.

Lot of thanks for the support. And thanks in Advance.

Emmanuel Mathew|||I reinstalled IIS and the server stated working fine now. I know its not the solution. But I made it working. Thanks a lot for your help.

Tuesday, March 27, 2012

Configuration file location different in BIDS?

I've been working on package configurations here, mainly trying to figure out what works, and how. If I use an XML configuration, and and don't specify the path, ie just typing in test.dtsconfig, it creates the config file on my desktop. When I execute the packge in BIDS, it seems to be looking in that location. If however, I execute the package manually on the filesystem, test.dtsconfig must be in the same directory as the package (which is what I would expect). Why does this work differently in BIDS. Also, if the package is deployed to a SQL server, where would the configuration file need to be in this case? Thanks for the help.

Configuration file paths in SSIS are absolute, not relative. hence, use the full path when defining your file. i can't explain why behaviour is different between BIDS and whatever other method you are using to execute but to be honest that is irrelevant if you define the location with an absolute path.

If you don't like the thought of absolute paths then indirect configurations are what you want! http://blogs.conchango.com/jamiethomson/archive/2005/11/02/2342.aspx

Deployingn to SQL Server makes no differrence. you still need an absolute path.

-Jamie

Tuesday, March 20, 2012

Conditionally entering flat file data into relational Stucture

Hi,

I'm working on importing some data into my database. The data is currently in a SQL Server Table. I'm new to working with triggers (or performing more complex sql commands for that matter) but am trying to use a trigger on a view(that is identical to the table being imported) to handle a bulk insert.

I was under the impression that the "inserted" table handles one record at a time. When I figured out that isn't the case, I felt stumped as to how to make importing decisions on each record.

I have a Research Project Table consisting of ID,ProjectNum,Title
Also, there is a ResearchProjectPeriod table consisting of ID,ProjectID,From,To,DirectCost,IndirectCost

I'd like to check for projectNum on the records to import and if it exists in my database then only create associated entry in ResearchProjectPeriod table. If there is no associated ProjectNum then I would like to create the project as well as create an associated ResearchProjectPeriod Record.

Thanks for your help.

StephenHi,

You could inport the data into a temp table and then go through the imported rows one by one or by batch.

Hope it helps!

Monday, March 19, 2012

Conditional sum based on visibility

Hi,

I have a report that is conditionally showing a textbox based on the previous entry that is working correctly.

My issue is that the non visible entries are still being added to my Sum statement at the end of the report.

I need a way to exclude an entry based on its visibility.

Any help would be greatly appreciated.

Are you using the Previous aggregate to get the previous entry? If you are not, then you can add a conditional, using the same expression for determining the visibility, to the SUM aggregate. For example, =SUM(IIF(HiddenExpression, 0, Fields!FieldName.Value))|||

Thanks for the response.

I am using the Previous function to control the visibility. The report needs to show the first entry for each particular company code, but not the duplicate entries.

For example: =Previous(Fields!Company_code.Value) = Fields!Company_code.Value

I tried adding a conditional with the same expression to determine if it should be included in the Sum, but that does not work.

Any other suggestions?

Thanks!

|||

Try handling it in the code (Report -> Report Properties -> Code)

Declare a public shared variable (integer/float) in the code and write a public function to sum up the values based on current company code and previous company code. Your code will look something like this in VB.Net:

Public Shared SumTotal as Integer

SumTotal = 0

Public Function CalculateSum(isCompanyCodeSame as Boolean, FieldValue as Integer) As String

If isCompanyCodeSame = False Then

SumTotal = SumTotal + FieldValue

End If

CalculateSum = ""

End Function

and

append this expression to any of the textboxes in your detail row:

Fields!FieldName.Value & Code.CalculateSum(Fields!Company_code.Value=Previous(Fields!Company_code.Value), Fields!FieldToBeSummed.Value)

And use Code.SumTotal to get the sum.

Shyam

|||

Thanks for the code!

It is working correctly now.

|||

I used the same method to stop displaying rows in a table after the 10th row. It works fine in VS 2005 but it acts wierd when I publish it to the production server. I count up the rows that are visible...

Public Shared VisibleRowTotal as Integer=0

Public Function CountVisibleRow(isVisible as Boolean) As String
If isVisible = False Then
VisibleRowTotal = VisibleRowTotal + 1
End If
CountVisibleRow = ""
End Function

Then I added a column in my report table to call the code...

=Code.CountVisibleRow(ReportItems!textbox54.Value) & " " & Code.VisibleRowTotal

Then I based my row visibility on the code value.

=IIF(Code.VisibleRowTotal>=10, True,False)

To get it to work the first time I had to rename the original report on the production server and then upload the new report. Once several users start hitting the report then no rows are visible or it's intermittent.

I'll admit I've have never used custom code in a report before. Is there something different I need to do when uploading an rdl with custom code? Am I handling the custom code properly?

|||
You should change the VisibleRowTotal variable to not be Shared. Having it be shared or static will cause each instance of the report to share the same total value. So, removing the modifier will allow each report instance to execute independently from one another.

Ian|||

Thanks Ian.

I had the issue where my totals were correct for the first time the report loaded, but the totals just kept incrementing when I used different filters on the report.

Taking Shared off of the variable resolved the issue.

Sunday, March 11, 2012

Conditional query on ASPNET page

Dear Friends,

I am working on search customer information page.

I have 5 search options,

Name,

Email,

Order Number,

Product Name,

Order Date

I am using check boxes, I need to allow admin to enter above information and click on search,

How will I make my query and sends to DB server to pull up records which satisfies where clause:

For example,

Select * from orders where Email = #Email#

This is simple, but I can not hardcode all queries, I don’t know in advance what different search option ADMIN may choose.

Any suggestion for logic or query make up,

Thanks,

Fahim.

So here are a couple suggestions that might help you with your task:

1. Look into calling system stored procedure sp_columns (http://msdn2.microsoft.com/en-us/library/ms176077.aspx) on the table to get the column metadata information.

Using this information you can then dynamically generate a query based on the check boxes selected by the user.

2, If you schema is simple and you already know the column information, then all you need to do is have a string that concatenates differect WHERE clauses based on the options selected and then submit the query when the user hits the search button.

HTH,

Wednesday, March 7, 2012

Conditional group footer sum

HI,
I am working with a developer who has an interesting problem. They have
data field in a sql table that is of a numeric value a second field that
tells whether or not the previous value is a debit or credit for a general
ledger.
They want to show on a report a sum of the numeric field in a group footer.
We have tried writing a conditional formula(=Iif(FieldB="dr",Sum(FieldA),o))
for a hidden field on the report in the detail row of a table and then using
the Reportitems Syntax to display that fields value in the group footer, but
we get an out of scope error.
Looking for possible suggestions, code sample, or alternatives. Changing
the data in the SQL table is not a possibility.
Thanks!!I recently tried doing something similar to this but I was getting a data
type error. I resolved it by making the following change:
Orig: sum(iif(Fields!Type.Value = 'Dr', Fields!Amount.Value, 0) --Got errors
New: sum(iif(Fields!Type.Value = 'Dr', Fields!Amount.Value,
Fields!Amount.Value*0)
I don't know why mulitplying by 0 gives the correct data type, but simply
putting a 0 in does not, but that is only variation (0, 0.0, 0.00, etc...) I
could find that worked.
"Mark" wrote:
> HI,
> I am working with a developer who has an interesting problem. They have
> data field in a sql table that is of a numeric value a second field that
> tells whether or not the previous value is a debit or credit for a general
> ledger.
> They want to show on a report a sum of the numeric field in a group footer.
> We have tried writing a conditional formula(=Iif(FieldB="dr",Sum(FieldA),o))
> for a hidden field on the report in the detail row of a table and then using
> the Reportitems Syntax to display that fields value in the group footer, but
> we get an out of scope error.
> Looking for possible suggestions, code sample, or alternatives. Changing
> the data in the SQL table is not a possibility.
> Thanks!!|||The reason why multiplying with 0 works is that it preserves the original
datatype of the numeric field (which could be anything like UInt16, Decimal,
etc.).
This should work (the constant value 0.0 is a System.Double at runtime):
=sum(iif(Fields!Type.Value = 'Dr', CDbl(Fields!Amount.Value), 0.0)
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Brandon Lunt" <BrandonLunt@.discussions.microsoft.com> wrote in message
news:9EAB31A6-E7CA-4912-82BC-A678EAE9CA0C@.microsoft.com...
> I recently tried doing something similar to this but I was getting a data
> type error. I resolved it by making the following change:
> Orig: sum(iif(Fields!Type.Value = 'Dr', Fields!Amount.Value, 0) --Got
errors
> New: sum(iif(Fields!Type.Value = 'Dr', Fields!Amount.Value,
> Fields!Amount.Value*0)
> I don't know why mulitplying by 0 gives the correct data type, but simply
> putting a 0 in does not, but that is only variation (0, 0.0, 0.00, etc...)
I
> could find that worked.
> "Mark" wrote:
> > HI,
> >
> > I am working with a developer who has an interesting problem. They have
> > data field in a sql table that is of a numeric value a second field that
> > tells whether or not the previous value is a debit or credit for a
general
> > ledger.
> >
> > They want to show on a report a sum of the numeric field in a group
footer.
> > We have tried writing a conditional
formula(=Iif(FieldB="dr",Sum(FieldA),o))
> > for a hidden field on the report in the detail row of a table and then
using
> > the Reportitems Syntax to display that fields value in the group
footer, but
> > we get an out of scope error.
> >
> > Looking for possible suggestions, code sample, or alternatives.
Changing
> > the data in the SQL table is not a possibility.
> >
> > Thanks!!

Saturday, February 25, 2012

Conditional computing

Hi everyone,
I'm working on a report that gives a summary of data in a sql server
database. The structure of the database is the following:
A company has one to many investments. These investments are for a certain
sector, are of a certain nature and are in a certain state. This gives us a
data model that ressembles this:
tblInvestments has a foreign key for the company, the sector and the state
tables.
Now, the report I have to do is a detail of the investments by sector. For
example, say we have "Primary", "Secondary", and "Manufacturing" as sectors,
the report must look like this:
Total investments for company x : 15
Sector Investments Active Total
invested
Primary 4 3 130
000$
Secondary 3 3 250
000$
Manufacturing 8 6 140
000$
The Investments column is simply a count of the investments for a particular
company. The Active column lists the count of all the investments that are
in the state "Active" and the Total invested is the sum of a field in the
Investments table for only the investments that are active. I've been
struggling for this problem for a while now and I'd like some input. Is
there a way to:
1) Do this in 1 view
2) List all the sectors even if there is no investments (to list a zero for
the other columns)
I tried to do two separate views for the simple total of the investments and
for the count of the investments and the total amount, but I can't get them
back together in one query (one line for each investment).
Any help would be appreciated.
ric.
hi eric,
It would have been more easier to give you solution, if you would have
posted sample table structure and data alongwith expected result set.
however on the basis of some information provided by you , the query given
in following example might be what you are looking for.
--sample data
create table tblInvestments (companyid int, sectorid int,
stateid int,
status varchar(10),
amount int)
go
create table company (companyid int primary key, companyname varchar(500))
go
create table sector(sectorid int primary key, sectorname varchar(500))
go
create table state(stateid int primary key, statename varchar(500))
go
insert into company values(1,'company1')
insert into company values(2,'company2')
insert into company values(3,'company3')
go
insert into sector values (1,'primary')
insert into sector values (2,'secondary')
insert into sector values (3,'manufacturing')
go
insert into state values (1,'CA')
insert into state values (2,'NJ')
insert into state values (3,'MA')
go
insert into tblinvestments values(1,1,1,'active',1000)
insert into tblinvestments values(1,1,1,'inactive',1000)
insert into tblinvestments values(2,1,1,'active',1000)
insert into tblinvestments values(1,2,1,'active',2000)
insert into tblinvestments values(2,2,1,'active',2000)
go
--required query
select b.companyname ,a.sectorname,
sum (case when c.companyid is null then 0 else 1 end ) 'investment' ,
sum(case c.status when 'active' then 1 else 0 end) 'active',
sum(case c.status when 'active' then c.amount else 0 end) 'total invested'
from sector a cross join company b
left outer join tblInvestments c
on a.sectorid = c.sectorid and b.companyid = c.companyid
group by a.sectorname, b.companyname
order by 1,2
compute sum (sum (case when c.companyid is null then 0 else 1 end )) by
b.companyname
Vishal Parkar
vgparkar@.yahoo.co.in | vgparkar@.hotmail.com

Friday, February 24, 2012

conditional color property based on date

I want to use an IIF statement to set the color property for a text box.
Here is my code that is not working:
=IIf(DateAdd('m', -6, Fields!Orig_expireDate.Value) <
Now(), "red", "black")Use " instead of '
( ' is a comment for vb, even in reporting services)
Mike G.
"ladydi_1226" <ladydi1226@.discussions.microsoft.com> wrote in message
news:92B486DB-EFFA-49BC-AEE3-76CBBF4A24AE@.microsoft.com...
>I want to use an IIF statement to set the color property for a text box.
> Here is my code that is not working:
> =IIf(DateAdd('m', -6, Fields!Orig_expireDate.Value) <
> Now(), "red", "black")

Sunday, February 19, 2012

condense this working SQL into an algorithm

What is listed below works but I would like to condense it into a loop. Any
ideas? Thank you. -Greg
-- peform substring at these locations in column 1,5,9,13,17,21,25
CREATE TABLE #one
(AreaCode varchar(50),
TimeZone varchar(50))
INSERT INTO #one
(AreaCode, TimeZone)
select distinct SUBSTRING(AreaCode, 1, 3) AS AreaCode,TimeZone
from ZipCodeDatabase_DELUXE
CREATE TABLE #two
(AreaCode varchar(50),
TimeZone varchar(50))
INSERT INTO #two
(AreaCode, TimeZone)
select distinct SUBSTRING(AreaCode, 5, 3) AS AreaCode,TimeZone
from ZipCodeDatabase_DELUXE
CREATE TABLE #three
(AreaCode varchar(50),
TimeZone varchar(50))
INSERT INTO #three
(AreaCode, TimeZone)
select distinct SUBSTRING(AreaCode, 9, 3) AS AreaCode,TimeZone
from ZipCodeDatabase_DELUXE
CREATE TABLE #four
(AreaCode varchar(50),
TimeZone varchar(50))
INSERT INTO #four
(AreaCode, TimeZone)
select distinct SUBSTRING(AreaCode, 13, 3) AS AreaCode,TimeZone
from ZipCodeDatabase_DELUXE
CREATE TABLE #five
(AreaCode varchar(50),
TimeZone varchar(50))
INSERT INTO #five
(AreaCode, TimeZone)
select distinct SUBSTRING(AreaCode, 17, 3) AS AreaCode,TimeZone
from ZipCodeDatabase_DELUXE
CREATE TABLE #six
(AreaCode varchar(50),
TimeZone varchar(50))
INSERT INTO #six
(AreaCode, TimeZone)
select distinct SUBSTRING(AreaCode, 21, 3) AS AreaCode,TimeZone
from ZipCodeDatabase_DELUXE
CREATE TABLE #seven
(AreaCode varchar(50),
TimeZone varchar(50))
INSERT INTO #seven
(AreaCode, TimeZone)
select distinct SUBSTRING(AreaCode, 25, 3) AS AreaCode,TimeZone
from ZipCodeDatabase_DELUXE
CREATE TABLE total
(AreaCode varchar(50),
TimeZone varchar(50))
insert into total
SELECT * FROM #one
UNION ALL
SELECT * FROM #two
UNION ALL
SELECT * FROM #three
UNION ALL
SELECT * FROM #four
UNION ALL
SELECT * FROM #five
UNION ALL
SELECT * FROM #six
UNION ALL
SELECT * FROM #sevenUntested:
INSERT total
SELECT DISTINCT SUBSTRING(AreaCode, a.Start * 4 + 1, 3)
, TimeZone
FROM ZipCodeDatabase_DELUXE, (SELECT 0 UNION SELECT 1 UNION SELECT 2
UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6) a (Start)
-Alan|||Awesome Alan ! Works perfectly! Now I have to digest what you did along with
my lunch. ;-) -appreciatively -greg
"Alan Samet" <alansamet@.gmail.com> wrote in message
news:1141750087.253473.75260@.z34g2000cwc.googlegroups.com...
> Untested:
> INSERT total
> SELECT DISTINCT SUBSTRING(AreaCode, a.Start * 4 + 1, 3)
> , TimeZone
> FROM ZipCodeDatabase_DELUXE, (SELECT 0 UNION SELECT 1 UNION SELECT 2
> UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6) a (Start)
> -Alan
>|||well, first lets break down your results into a set of UNIONed queries:
INSERT total
SELECT SUBSTRING(AreaCode, 1, 3), TimeZone FROM ...
UNION
SELECT SUBSTRING(AreaCode, 1, 3), TimeZone FROM ...
Simple enough, right? Next, when you have multiple entities in your
FROM clause with no JOIN expression, SQL extrapolates all combinations.
SELECT *
FROM (SELECT 1 Number UNION SELECT 2) a
, (SELECT 'A' UNION SELECT 'B') b (Letter)
This is what I did, only I used a subquery that unioned the numbers 0
through 6. I recognized a linear pattern of your start position, so I
used that in the SUBSTRING function. While I could've not used that
formula and used the values 1, 5, 9, et cetera in my UNIONed list of
numbers, I thought it made things a little cleaner to use the formula
in the SUBSTRING function. The above query shows two ways of naming
your columns. I used the latter.
-Alan|||Your DDL sucks. Please give an example of a time_zone that is CHAR(50)
instead of CHAR(3)' Likewise area_)code? etc.
Why do your tables all have no keys' Don't you know that there are no
loops in a declarative language? There are UNIONs in SQL and you can
use them to split up this mess. But why would have such poor data in
the first place?|||Your DDL sucks. Please give an example of a time_zone that is CHAR(50)
instead of CHAR(3)' Likewise area_)code? etc.
Why do your tables all have no keys' Don't you know that there are no
loops in a declarative language? There are UNIONs in SQL and you can
use them to split up this mess. But why would have such poor data in
the first place?|||Your DDL sucks. Please give an example of a time_zone that is CHAR(50)
instead of CHAR(3)' Likewise area_)code? etc.
Why do your tables all have no keys' Don't you know that there are no
loops in a declarative language? There are UNIONs in SQL and you can
use them to split up this mess. But why would have such poor data in
the first place?|||--CELKO-- (jcelko212@.earthlink.net) writes:
> Your DDL sucks. Please give an example of a time_zone that is CHAR(50)
> instead of CHAR(3)' Likewise area_)code? etc.
char(3) for a time zone? Need char(5), sign + four digits.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||>> har(3) for a time zone? Need char(5), sign + four digits. <<
That is a time displacement; a zone is "PST', etc. Also, I seem to
remember that we got rid of the "old fractional hours" displacements a
few yers ago, so you can use an integer off of UTC.|||--CELKO-- wrote:
> That is a time displacement; a zone is "PST', etc. Also, I seem to
> remember that we got rid of the "old fractional hours" displacements a
> few yers ago, so you can use an integer off of UTC.
Except there are still places in the world which are, for instance, 5
1/2 hours ahead of UTC (India)
Damien

Tuesday, February 14, 2012

Concurrency issues in trees

Hi NG,
My indented Bill of Materials (BOM) report has been working for some time
now. It is time to deal with the issue of multiuser operations and
concurrency. My approach has been to use the tree spanning algorithm
suggested by Steve Kass. This stored procedure builds a table called
'ibom'. Next, my application reads ibom and places the result in the client
machine's XML file. Finally, a Crystal Report reads the XML file and prints
the report. This approach works fine as long as there is only one user
running the application. All hell would break loose if two or more users
were constructing the ibom table. The code at the end of this post shows my
C# application first building ibom and then reading ibom. No harm would
come if the ibom table was locked from the point of its creation until the
last row was read by my method WriteXML(). How do you set a lock in the
stored procedure TREESPAN (not shown in this post) and remove it after the
execution of WriteXML()? It is perfectly OK to DROP TABLE ibom after the
WriteXML(). Also note that this code will be infrequently run so locking
ibom will have little effect on performance. However, a garbaged ibom table
would be a disaster!
Thank you,
Bob
--
Robert Schuldenfrei
S. I. Inc.
32 Ridley Road
Dedham, MA 02026
bob@.s-i-inc.com
781/329-4828
private void LoadIbom(string treeSpan)
{
//--Call the stored procedure--
mcs3Connection.Open();
SqlCommand cmd = new SqlCommand(treeSpan, mcs3Connection);
cmd.CommandType = CommandType.Text;
SqlDataReader reader = cmd.ExecuteReader();
reader.Close();
mcs3Connection.Close();
}
//--Method to getting ibom table and writing XML--
private void WriteXML()
{
//--SQL code to get ibom table--
selectStmt = "SELECT "
+ "ps_PartIndex, "
+ "ps_ParentIndex, "
+ "ps_PartNo, "
+ "ps_Qty_Per, "
+ "Level, "
+ "ps_Effectivity, "
+ "ps_Add_Del, "
+ "ps_Ref, "
+ "path "
+ "FROM ibom "
+ "ORDER BY path ";
SqlCommand selectCmd = new SqlCommand(selectStmt, mcs3Connection);
mcs3Connection.Open();
try
{
bomReader = selectCmd.ExecuteReader();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\n"
+ ex.GetType().ToString() + "\n\n"
+ ex.StackTrace, "Exception");
mcs3Connection.Close();
}
while (bomReader.Read()) //read entire ibom table
{
strComponent = (string) bomReader["ps_PartNo"];
itemMaster = ItemMasterTbl.GetItemMaster(strComponent);
//format issues corrected here
intLevel = (int) bomReader["Level"];
if (intLevel == 0) BlankRow();
strComponent = " ".PadLeft(intLevel*3) + strComponent;
strLevel = intLevel.ToString();
decQtyPer = (decimal) bomReader["ps_Qty_Per"];
if (decQtyPer == 0) strQtyPer = "0.000000";
else strQtyPer = decQtyPer.ToString();
counter++;
xmlOut.WriteStartElement("PS1307");
xmlOut.WriteAttributeString("ps_component", strComponent);
xmlOut.WriteElementString("ps_parent", strDummy);
xmlOut.WriteElementString("ps_qty_per", strQtyPer);
xmlOut.WriteElementString("ps_desc", (string) itemMaster.IM_Desc);
xmlOut.WriteElementString("ps_phantom_flag", (string)
itemMaster.IM_phantom_flag);
xmlOut.WriteElementString("ps_UOM", (string) itemMaster.IM_UOM);
xmlOut.WriteElementString("ps_pur_mfg_code", (string)
itemMaster.IM_pur_mfg_code);
xmlOut.WriteElementString("ps_effectivity", (string)
bomReader["ps_Effectivity"]);
xmlOut.WriteElementString("ps_add_delete", (string)
bomReader["ps_Add_Del"]);
xmlOut.WriteElementString("ps_ref", (string) bomReader["ps_Ref"]);
xmlOut.WriteElementString("ps_level", strLevel);
xmlOut.WriteEndElement(); //PS1307
}
mcs3Connection.Close();
}
//----robert,
you can virtually partition your ibom table by adding a column (say, 'user')
with default of suser_sid() or suser_sname(), and reference this column in
where clause:
where user=suser_sname()
also, don't drop the ibom table, but rather delete ibom where
user=suser_sname()
hth
dean
"Robert Schuldenfrei" <schuldenfrei@.comcast.net> wrote in message
news:Y4SdnaXXUMpV14_fRVn-jg@.comcast.com...
> Hi NG,
> My indented Bill of Materials (BOM) report has been working for some time
> now. It is time to deal with the issue of multiuser operations and
> concurrency. My approach has been to use the tree spanning algorithm
> suggested by Steve Kass. This stored procedure builds a table called
> 'ibom'. Next, my application reads ibom and places the result in the
client
> machine's XML file. Finally, a Crystal Report reads the XML file and
prints
> the report. This approach works fine as long as there is only one user
> running the application. All hell would break loose if two or more users
> were constructing the ibom table. The code at the end of this post shows
my
> C# application first building ibom and then reading ibom. No harm would
> come if the ibom table was locked from the point of its creation until the
> last row was read by my method WriteXML(). How do you set a lock in the
> stored procedure TREESPAN (not shown in this post) and remove it after the
> execution of WriteXML()? It is perfectly OK to DROP TABLE ibom after the
> WriteXML(). Also note that this code will be infrequently run so locking
> ibom will have little effect on performance. However, a garbaged ibom
table
> would be a disaster!
> Thank you,
> Bob
> --
> Robert Schuldenfrei
> S. I. Inc.
> 32 Ridley Road
> Dedham, MA 02026
> bob@.s-i-inc.com
> 781/329-4828
> private void LoadIbom(string treeSpan)
> {
> //--Call the stored
procedure--
> mcs3Connection.Open();
> SqlCommand cmd = new SqlCommand(treeSpan, mcs3Connection);
> cmd.CommandType = CommandType.Text;
> SqlDataReader reader = cmd.ExecuteReader();
> reader.Close();
> mcs3Connection.Close();
> }
> //--Method to getting ibom table and writing
XML--
> private void WriteXML()
> {
> //--SQL code to get ibom
table--
> selectStmt = "SELECT "
> + "ps_PartIndex, "
> + "ps_ParentIndex, "
> + "ps_PartNo, "
> + "ps_Qty_Per, "
> + "Level, "
> + "ps_Effectivity, "
> + "ps_Add_Del, "
> + "ps_Ref, "
> + "path "
> + "FROM ibom "
> + "ORDER BY path ";
> SqlCommand selectCmd = new SqlCommand(selectStmt, mcs3Connection);
> mcs3Connection.Open();
> try
> {
> bomReader = selectCmd.ExecuteReader();
> }
> catch (Exception ex)
> {
> MessageBox.Show(ex.Message + "\n\n"
> + ex.GetType().ToString() + "\n\n"
> + ex.StackTrace, "Exception");
> mcs3Connection.Close();
> }
> while (bomReader.Read()) //read entire ibom table
> {
> strComponent = (string) bomReader["ps_PartNo"];
> itemMaster = ItemMasterTbl.GetItemMaster(strComponent);
> //format issues corrected here
> intLevel = (int) bomReader["Level"];
> if (intLevel == 0) BlankRow();
> strComponent = " ".PadLeft(intLevel*3) + strComponent;
> strLevel = intLevel.ToString();
> decQtyPer = (decimal) bomReader["ps_Qty_Per"];
> if (decQtyPer == 0) strQtyPer = "0.000000";
> else strQtyPer = decQtyPer.ToString();
> counter++;
> xmlOut.WriteStartElement("PS1307");
> xmlOut.WriteAttributeString("ps_component", strComponent);
> xmlOut.WriteElementString("ps_parent", strDummy);
> xmlOut.WriteElementString("ps_qty_per", strQtyPer);
> xmlOut.WriteElementString("ps_desc", (string) itemMaster.IM_Desc);
> xmlOut.WriteElementString("ps_phantom_flag", (string)
> itemMaster.IM_phantom_flag);
> xmlOut.WriteElementString("ps_UOM", (string) itemMaster.IM_UOM);
> xmlOut.WriteElementString("ps_pur_mfg_code", (string)
> itemMaster.IM_pur_mfg_code);
> xmlOut.WriteElementString("ps_effectivity", (string)
> bomReader["ps_Effectivity"]);
> xmlOut.WriteElementString("ps_add_delete", (string)
> bomReader["ps_Add_Del"]);
> xmlOut.WriteElementString("ps_ref", (string) bomReader["ps_Ref"]);
> xmlOut.WriteElementString("ps_level", strLevel);
> xmlOut.WriteEndElement(); //PS1307
> }
> mcs3Connection.Close();
> }
> //----
>|||Hi Dean and NG,
Thank you for the "very excellent" suggestion. I am an "old dog" and I have
trouble thinking in sets of rows. I am sure that will produce the desired
result with a trivial amount of additional code. This technique will come
in handy in a number of situations beyond my immediate issue.
Sincerely,
Bob
--
Robert Schuldenfrei
S. I. Inc.
32 Ridley Road
Dedham, MA 02026
bob@.s-i-inc.com
781/329-4828
"Dean" <deanv@.nospam.spin.hr> wrote in message
news:uSMRNc5EFHA.560@.TK2MSFTNGP15.phx.gbl...
> robert,
> you can virtually partition your ibom table by adding a column (say,
> 'user')
> with default of suser_sid() or suser_sname(), and reference this column in
> where clause:
> where user=suser_sname()
> also, don't drop the ibom table, but rather delete ibom where
> user=suser_sname()
> hth
> dean
> "Robert Schuldenfrei" <schuldenfrei@.comcast.net> wrote in message
> news:Y4SdnaXXUMpV14_fRVn-jg@.comcast.com...
> client
> prints
> my
> table

Concurrency Issues

Is there any way to get the sample below working so that both "threads" are guaranteed to get unique and incrementing values?

I'm suspecting the answer is no. You can use transactions on completely database oriented operations that read/write to a database and complete. But there aren't complete synchronization controls for operations like below that try to return a value to an outside process.

IF OBJECT_ID('SimpleTable') IS NOT NULL
DROP TABLE SimpleTable

CREATE TABLE SimpleTable (
A INTEGER
)
INSERT INTO SimpleTable (A) VALUES (1)

-- Run in one window
DECLARE @.value INTEGER

BEGIN TRANSACTION
SELECT TOP 1 @.value = A FROM SimpleTable
WAITFOR DELAY '00:00:05'
UPDATE SimpleTable SET A = @.value + 1
COMMIT TRANSACTION

SELECT @.value
SELECT A FROM SimpleTable

-- Run in a second window
DECLARE @.value INTEGER

BEGIN TRANSACTION
SELECT TOP 1 @.value = A FROM SimpleTable
UPDATE SimpleTable SET A = @.value + 1
COMMIT TRANSACTION

SELECT @.value
SELECT A FROM SimpleTableUse an identity property, instead of code. While you might loose a few values if threads (spids) die for some reason, and you might cause other holes by deleting rows, the values will be unique and monotonically increasing.

-PatP|||Use an identity property, instead of code. While you might loose a few values if threads (spids) die for some reason, and you might cause other holes by deleting rows, the values will be unique and monotonically increasing.

-PatP

Actually, I did just that. However, I was kind of curious if it was possible to acheive with transactions or with some explicit locking calls.|||There definitely is a way to do it using just SQL statements with Transact-SQL's locking model. The identity process is simpler and supported though.

-PatP|||You'll need to use (TABLOCK) or (UPDLOCK) as table hints to ensure ACID properties of a transaction while attempting to generate an artificial IDENTITY value.|||You'll need to use (TABLOCK) or (UPDLOCK) as table hints to ensure ACID properties of a transaction while attempting to generate an artificial IDENTITY value.

Thank you. That will work. Except BOL calls those locking "hints" which means the solution isn't guaranteed to work even though it probably will on today's implementations.|||I don't see how it will not work, but you're free to refute it.|||It won't work if a future implementation (either a future version or service pack of SQL Server) decides to ignore the locking "hint". The database engine is completely free to obey or ignore "hints" at will so you shouldn't base an algorithm on that.

I don't see how it will not work, but you're free to refute it.

Concating values of a Column based on a Group

Hello All,
I'm working on optimizing a SP that is Cursor driven which is not able to
Scale (for obvious
reasons) as the number of records satisfying the Report Criteria increases.
I have been able to re-write the Cursor based SP to a Set based SP to a
large extent. However,
I'm stuck with one aspect for which I might have to use a cursor. Here is
what I have to do :
CREATE TABLE [dbo].[MemberBooks] (
[MemberID] [int] NOT NULL ,
[Book_Description] [varchar] (1000) NULL
) ON [PRIMARY]
GO
insert into MemberBooks(100,'The Bourne Identity')
insert into MemberBooks(100,'The Bourne Legacy')
insert into MemberBooks(100,'The Bourne Supremacy')
insert into MemberBooks(100,'The Bourne Ultimatum')
insert into MemberBooks(200,'Angels and Demons')
insert into MemberBooks(200,'The Main Enemy')
insert into MemberBooks(200,'Globalization and its Discontents')
insert into MemberBooks(200,'The Roaring Nineties')
insert into MemberBooks(400,'Open Secrets')
insert into MemberBooks(400,'Software Release Methodology')
insert into MemberBooks(600,'The Da Vinci Code')
insert into MemberBooks(600,'The coming of the Barbarians')
I need to write a query that would return for each memberid the following :
100, "The Bourne Identity;The Bourne Legacy;The Bourne Supremacy;The Bourne
Ultimatum"
200, "Angels and Demons;The Main Enemy;Globalization and its Discontents;The
Roaring Nineties"
400, "Open Secrets;Software Release Methodology"
600, "The Da Vinci Code;The coming of the Barbarians"
I'm know how to get values in a column as a string using the form
select @.Book_Description = @.Book_Description + ';' + Book_Description from
MemberBooks
but that would return all the books which is not what I want, ie,
The Bourne Identity;The Bourne Legacy;The Bourne Supremacy;The Bourne
Ultimatum;Angels and Demons;The Main Enemy;Globalization and its
Discontents;The Roaring Nineties;Open Secrets;Software Release
Methodology;The Da Vinci Code;The coming of the Barbarians
However, I cannot use a group by in this to get records of the form
"The Bourne Identity;The Bourne Legacy;The Bourne Supremacy;The Bourne
Ultimatum"
"Angels and Demons;The Main Enemy;Globalization and its Discontents;The
Roaring Nineties"
"Open Secrets;Software Release Methodology"
"The Da Vinci Code;The coming of the Barbarians"
Is a Cursor the only choice ?
Gopigopi
Some ideas
create table w
(
id int,
t varchar(50)
)
insert into w values (1,'abc')
insert into w values (1,'def')
insert into w values (1,'ghi')
insert into w values (2,'ABC')
insert into w values (2,'DEF')
select * from w
create function dbo.fn_my ( @.id int)
returns varchar(100)
as
begin
declare @.w varchar(100)
set @.w=''
select @.w=@.w+t+',' from w where id=@.id
return @.w
end
select id,
dbo.fn_my (dd.id)
from
(
select distinct id from w
)
as dd
drop function dbo.fn_my
"gopi" <rgopinath@.hotmail.com> wrote in message
news:e0TwPe8IFHA.3832@.TK2MSFTNGP12.phx.gbl...
> Hello All,
> I'm working on optimizing a SP that is Cursor driven which is not able to
> Scale (for obvious
> reasons) as the number of records satisfying the Report Criteria
increases.
> I have been able to re-write the Cursor based SP to a Set based SP to a
> large extent. However,
> I'm stuck with one aspect for which I might have to use a cursor. Here is
> what I have to do :
>
> CREATE TABLE [dbo].[MemberBooks] (
> [MemberID] [int] NOT NULL ,
> [Book_Description] [varchar] (1000) NULL
> ) ON [PRIMARY]
> GO
> insert into MemberBooks(100,'The Bourne Identity')
> insert into MemberBooks(100,'The Bourne Legacy')
> insert into MemberBooks(100,'The Bourne Supremacy')
> insert into MemberBooks(100,'The Bourne Ultimatum')
> insert into MemberBooks(200,'Angels and Demons')
> insert into MemberBooks(200,'The Main Enemy')
> insert into MemberBooks(200,'Globalization and its Discontents')
> insert into MemberBooks(200,'The Roaring Nineties')
> insert into MemberBooks(400,'Open Secrets')
> insert into MemberBooks(400,'Software Release Methodology')
> insert into MemberBooks(600,'The Da Vinci Code')
> insert into MemberBooks(600,'The coming of the Barbarians')
>
> I need to write a query that would return for each memberid the following
:
> 100, "The Bourne Identity;The Bourne Legacy;The Bourne Supremacy;The
Bourne
> Ultimatum"
> 200, "Angels and Demons;The Main Enemy;Globalization and its
Discontents;The
> Roaring Nineties"
> 400, "Open Secrets;Software Release Methodology"
> 600, "The Da Vinci Code;The coming of the Barbarians"
> I'm know how to get values in a column as a string using the form
> select @.Book_Description = @.Book_Description + ';' + Book_Description from
> MemberBooks
> but that would return all the books which is not what I want, ie,
> The Bourne Identity;The Bourne Legacy;The Bourne Supremacy;The Bourne
> Ultimatum;Angels and Demons;The Main Enemy;Globalization and its
> Discontents;The Roaring Nineties;Open Secrets;Software Release
> Methodology;The Da Vinci Code;The coming of the Barbarians
>
> However, I cannot use a group by in this to get records of the form
> "The Bourne Identity;The Bourne Legacy;The Bourne Supremacy;The Bourne
> Ultimatum"
> "Angels and Demons;The Main Enemy;Globalization and its Discontents;The
> Roaring Nineties"
> "Open Secrets;Software Release Methodology"
> "The Da Vinci Code;The coming of the Barbarians"
> Is a Cursor the only choice ?
> Gopi
>|||Please, take a look to this post.
[url]http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.pu
blic.sqlserver.programming&mid=e5ed7714-8c9b-41a9-a126-2aac89974053&sloc=en-us[/ur
l]
AMB
"gopi" wrote:

> Hello All,
> I'm working on optimizing a SP that is Cursor driven which is not able to
> Scale (for obvious
> reasons) as the number of records satisfying the Report Criteria increases
.
> I have been able to re-write the Cursor based SP to a Set based SP to a
> large extent. However,
> I'm stuck with one aspect for which I might have to use a cursor. Here is
> what I have to do :
>
> CREATE TABLE [dbo].[MemberBooks] (
> [MemberID] [int] NOT NULL ,
> [Book_Description] [varchar] (1000) NULL
> ) ON [PRIMARY]
> GO
> insert into MemberBooks(100,'The Bourne Identity')
> insert into MemberBooks(100,'The Bourne Legacy')
> insert into MemberBooks(100,'The Bourne Supremacy')
> insert into MemberBooks(100,'The Bourne Ultimatum')
> insert into MemberBooks(200,'Angels and Demons')
> insert into MemberBooks(200,'The Main Enemy')
> insert into MemberBooks(200,'Globalization and its Discontents')
> insert into MemberBooks(200,'The Roaring Nineties')
> insert into MemberBooks(400,'Open Secrets')
> insert into MemberBooks(400,'Software Release Methodology')
> insert into MemberBooks(600,'The Da Vinci Code')
> insert into MemberBooks(600,'The coming of the Barbarians')
>
> I need to write a query that would return for each memberid the following
:
> 100, "The Bourne Identity;The Bourne Legacy;The Bourne Supremacy;The Bourn
e
> Ultimatum"
> 200, "Angels and Demons;The Main Enemy;Globalization and its Discontents;T
he
> Roaring Nineties"
> 400, "Open Secrets;Software Release Methodology"
> 600, "The Da Vinci Code;The coming of the Barbarians"
> I'm know how to get values in a column as a string using the form
> select @.Book_Description = @.Book_Description + ';' + Book_Description from
> MemberBooks
> but that would return all the books which is not what I want, ie,
> The Bourne Identity;The Bourne Legacy;The Bourne Supremacy;The Bourne
> Ultimatum;Angels and Demons;The Main Enemy;Globalization and its
> Discontents;The Roaring Nineties;Open Secrets;Software Release
> Methodology;The Da Vinci Code;The coming of the Barbarians
>
> However, I cannot use a group by in this to get records of the form
> "The Bourne Identity;The Bourne Legacy;The Bourne Supremacy;The Bourne
> Ultimatum"
> "Angels and Demons;The Main Enemy;Globalization and its Discontents;The
> Roaring Nineties"
> "Open Secrets;Software Release Methodology"
> "The Da Vinci Code;The coming of the Barbarians"
> Is a Cursor the only choice ?
> Gopi
>
>