I have a SQL table comprised of 31 columns.
The first column is simply an id column, the next 30 columns are labelled
[1],[2]...[30].
The numerical columns have a tinyint type and the data stored is either 1 or
null.
I wish to count the number of times a one appears in one column
simultaneously with another column:
eg count the number of times 1 appears in column [1] and 1 also appears in
column[15] in the same row:
Column [1] Column[15]
1 1 Count this
1 Don't count this
1 1 add 1 to the count
1 1 add 1 to the count
1 Don't count this
1 Don't count this
1 1 add 1 to the count
1 1 add 1 to the count,
etc.
The following has been suggested to me as a possible solution:
Imports MWFN
Partial Class MembersPages_My Page
Inherits System.Web.UI.P age
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim pairsAdapter As New MWFNTableAdapte rs.MWFNTableAda pter
Dim pairs As MWFN.MWFNDataTa ble
pairs = pairsAdapter.Ge tData
Dim myColumns As Data.DataColumn Collection = pairs.Columns
Dim columnA As Data.DataColumn
Dim columnB As Data.DataColumn
Dim num3 As Hashtable
For Each columnA In myColumns
If columnA.ColumnN ame <"Id" Then
For Each columnB In myColumns
If columnB.ColumnN ame <"Id" And columnB.Ordinal >
columnA.Ordinal Then
'if columnB's name doesn't equal Id and columnB's
position number is over columnA's, sum columnA and columnB
num3.Add(column A.ColumnName & "," &
columnB.ColumnN ame, pairs.Compute(" SUM(" & columnA.ColumnN ame & ") + SUM( " &
columnB.ColumnN ame & ")", ""))
End If
Next
End If
Next
End Sub
End Class
I have used a dataset to obtain the columns from the database datatable in
an effort to use a data access layer in my project. The dataset is MWFN.
The above code produces the following:
Warning: num3 is used before it has been assigned a value.
And when the programme is run:
Expecting a single column argument with possible child qualifier.
At this point in time , the code only sums/counts two columns. I will wish
to broaden that to sum/count 3 , 4 and possibly 5 columns, so the code needs
to be extensible. The number of columns will alos vary (probably from 27 to
59).
It doesn't matter if your suggestion is to use transact sql is a stored
procedure before the data gets to the project, or use vb as per the above
mentioned suggestion.
Any assistance would be appreciated.
Thank you
onecorp
Can anyone help point me in the right direction 4 2274
Hi onecorp,
I don't get this. Are you saying that the datatable can have a variable
number of columns? Can you provide the table definition? If the number of
columns is going to change when you go looking for the data then maybe they
should be rows in an other table instead.
PGC
"onecorp" <on*****@commun ity.nospamwrote in message
news:1D******** *************** ***********@mic rosoft.com...
>I have a SQL table comprised of 31 columns.
The first column is simply an id column, the next 30 columns are labelled
[1],[2]...[30].
The numerical columns have a tinyint type and the data stored is either 1
or
null.
I wish to count the number of times a one appears in one column
simultaneously with another column:
eg count the number of times 1 appears in column [1] and 1 also appears in
column[15] in the same row:
Column [1] Column[15]
1 1 Count this
1 Don't count this
1 1 add 1 to the count
1 1 add 1 to the count
1 Don't count this
1 Don't count this
1 1 add 1 to the count
1 1 add 1 to the count,
etc.
The following has been suggested to me as a possible solution:
Imports MWFN
Partial Class MembersPages_My Page
Inherits System.Web.UI.P age
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim pairsAdapter As New MWFNTableAdapte rs.MWFNTableAda pter
Dim pairs As MWFN.MWFNDataTa ble
pairs = pairsAdapter.Ge tData
Dim myColumns As Data.DataColumn Collection = pairs.Columns
Dim columnA As Data.DataColumn
Dim columnB As Data.DataColumn
Dim num3 As Hashtable
For Each columnA In myColumns
If columnA.ColumnN ame <"Id" Then
For Each columnB In myColumns
If columnB.ColumnN ame <"Id" And columnB.Ordinal >
columnA.Ordinal Then
'if columnB's name doesn't equal Id and columnB's
position number is over columnA's, sum columnA and columnB
num3.Add(column A.ColumnName & "," &
columnB.ColumnN ame, pairs.Compute(" SUM(" & columnA.ColumnN ame & ") +
SUM( " &
columnB.ColumnN ame & ")", ""))
End If
Next
End If
Next
End Sub
End Class
I have used a dataset to obtain the columns from the database datatable in
an effort to use a data access layer in my project. The dataset is MWFN.
The above code produces the following:
Warning: num3 is used before it has been assigned a value.
And when the programme is run:
Expecting a single column argument with possible child qualifier.
At this point in time , the code only sums/counts two columns. I will wish
to broaden that to sum/count 3 , 4 and possibly 5 columns, so the code
needs
to be extensible. The number of columns will alos vary (probably from 27
to
59).
It doesn't matter if your suggestion is to use transact sql is a stored
procedure before the data gets to the project, or use vb as per the above
mentioned suggestion.
Any assistance would be appreciated.
Thank you
onecorp
Can anyone help point me in the right direction
Hi PGC,
Thank you for your reply.
No the datatable cannot have a variable number of columns. There are a
number of different datatables. The simplest has 27 columns, the most complex
has 59 columns.
Regards
Onecorp
"PGC" wrote:
Hi onecorp,
I don't get this. Are you saying that the datatable can have a variable
number of columns? Can you provide the table definition? If the number of
columns is going to change when you go looking for the data then maybe they
should be rows in an other table instead.
PGC
"onecorp" <on*****@commun ity.nospamwrote in message
news:1D******** *************** ***********@mic rosoft.com...
I have a SQL table comprised of 31 columns.
The first column is simply an id column, the next 30 columns are labelled
[1],[2]...[30].
The numerical columns have a tinyint type and the data stored is either 1
or
null.
I wish to count the number of times a one appears in one column
simultaneously with another column:
eg count the number of times 1 appears in column [1] and 1 also appears in
column[15] in the same row:
Column [1] Column[15]
1 1 Count this
1 Don't count this
1 1 add 1 to the count
1 1 add 1 to the count
1 Don't count this
1 Don't count this
1 1 add 1 to the count
1 1 add 1 to the count,
etc.
The following has been suggested to me as a possible solution:
Imports MWFN
Partial Class MembersPages_My Page
Inherits System.Web.UI.P age
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim pairsAdapter As New MWFNTableAdapte rs.MWFNTableAda pter
Dim pairs As MWFN.MWFNDataTa ble
pairs = pairsAdapter.Ge tData
Dim myColumns As Data.DataColumn Collection = pairs.Columns
Dim columnA As Data.DataColumn
Dim columnB As Data.DataColumn
Dim num3 As Hashtable
For Each columnA In myColumns
If columnA.ColumnN ame <"Id" Then
For Each columnB In myColumns
If columnB.ColumnN ame <"Id" And columnB.Ordinal >
columnA.Ordinal Then
'if columnB's name doesn't equal Id and columnB's
position number is over columnA's, sum columnA and columnB
num3.Add(column A.ColumnName & "," &
columnB.ColumnN ame, pairs.Compute(" SUM(" & columnA.ColumnN ame & ") +
SUM( " &
columnB.ColumnN ame & ")", ""))
End If
Next
End If
Next
End Sub
End Class
I have used a dataset to obtain the columns from the database datatable in
an effort to use a data access layer in my project. The dataset is MWFN.
The above code produces the following:
Warning: num3 is used before it has been assigned a value.
And when the programme is run:
Expecting a single column argument with possible child qualifier.
At this point in time , the code only sums/counts two columns. I will wish
to broaden that to sum/count 3 , 4 and possibly 5 columns, so the code
needs
to be extensible. The number of columns will alos vary (probably from 27
to
59).
It doesn't matter if your suggestion is to use transact sql is a stored
procedure before the data gets to the project, or use vb as per the above
mentioned suggestion.
Any assistance would be appreciated.
Thank you
onecorp
Can anyone help point me in the right direction
I have run a sql suggestion and had the following queries,:
A)
(I made one small adjustment to your first suggestion in order to exclude
the Id column from the query, as follows:
If @Cols <'Id'
Set @qry='Select Count(*) From SPF Where (' + @qry + ')>1'
--Print @qry
Execute(@qry)
)
I executed the query on a table of 30 columns (adjusted the count as
necessary) using columns labelled 1, 2, and 3 . It returned a value of 34,
however, the answer should have been 3. Three is the number of times that one
simultaneously appears in each of the aforementioned columns ie . I only
wish to count the number or times that '1' appears in the nominted columns
simultaneously, whether I am checking two columns at a time or three columns
( or even 4 columns....whic h is why I thought that the query should be built
in managed code(VB .net) using SQL CLR ?????).
B)When I tried to use a table with 38 columns , I received the following
error:
Msg 217, Level 16, State 1, Procedure spMyTest2, Line 45
Maximum stored procedure, function, trigger, or view nesting level exceeded
(limit 32).
even after ensuring that I adjusted the count correctly....
C) This procedure appears to only return one value based on inputting the
paramters as indicated. For a table that contains 38 columns, there should be
8436 values. How do I return a list of all the combinations, not just one?
......Hence I thought managed code SQL CLR should be used. Does anyone have
any suggestions please ?
Any assistance would be appreciated.
Thank you
Onecorp
"onecorp" wrote:
Hi PGC,
Thank you for your reply.
No the datatable cannot have a variable number of columns. There are a
number of different datatables. The simplest has 27 columns, the most complex
has 59 columns.
Regards
Onecorp
"PGC" wrote:
Hi onecorp,
I don't get this. Are you saying that the datatable can have a variable
number of columns? Can you provide the table definition? If the number of
columns is going to change when you go looking for the data then maybe they
should be rows in an other table instead.
PGC
"onecorp" <on*****@commun ity.nospamwrote in message
news:1D******** *************** ***********@mic rosoft.com...
>I have a SQL table comprised of 31 columns.
The first column is simply an id column, the next 30 columns are labelled
[1],[2]...[30].
The numerical columns have a tinyint type and the data stored is either 1
or
null.
I wish to count the number of times a one appears in one column
simultaneously with another column:
>
eg count the number of times 1 appears in column [1] and 1 also appears in
column[15] in the same row:
>
Column [1] Column[15]
1 1 Count this
1 Don't count this
1 1 add 1 to the count
1 1 add 1 to the count
1 Don't count this
1 Don't count this
1 1 add 1 to the count
1 1 add 1 to the count,
etc.
>
The following has been suggested to me as a possible solution:
>
>
Imports MWFN
>
Partial Class MembersPages_My Page
>
Inherits System.Web.UI.P age
>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim pairsAdapter As New MWFNTableAdapte rs.MWFNTableAda pter
>
Dim pairs As MWFN.MWFNDataTa ble
>
pairs = pairsAdapter.Ge tData
>
Dim myColumns As Data.DataColumn Collection = pairs.Columns
Dim columnA As Data.DataColumn
Dim columnB As Data.DataColumn
Dim num3 As Hashtable
>
For Each columnA In myColumns
>
If columnA.ColumnN ame <"Id" Then
>
For Each columnB In myColumns
>
If columnB.ColumnN ame <"Id" And columnB.Ordinal >
columnA.Ordinal Then
>
'if columnB's name doesn't equal Id and columnB's
position number is over columnA's, sum columnA and columnB
>
num3.Add(column A.ColumnName & "," &
columnB.ColumnN ame, pairs.Compute(" SUM(" & columnA.ColumnN ame & ") +
SUM( " &
columnB.ColumnN ame & ")", ""))
>
End If
Next
End If
Next
End Sub
End Class
>
I have used a dataset to obtain the columns from the database datatable in
an effort to use a data access layer in my project. The dataset is MWFN.
The above code produces the following:
Warning: num3 is used before it has been assigned a value.
And when the programme is run:
Expecting a single column argument with possible child qualifier.
>
At this point in time , the code only sums/counts two columns. I will wish
to broaden that to sum/count 3 , 4 and possibly 5 columns, so the code
needs
to be extensible. The number of columns will alos vary (probably from 27
to
59).
>
It doesn't matter if your suggestion is to use transact sql is a stored
procedure before the data gets to the project, or use vb as per the above
mentioned suggestion.
Any assistance would be appreciated.
Thank you
>
onecorp
>
>
Can anyone help point me in the right direction
There are a number of ways to solve your issue, here is one that I think
will help.
Create a temp (@MatchCounts) table for to hold values.
@MatchCounts
FieldList Varchar(255) Not Null
MatchCount Int Not Null
Loop over the combinations you want to retrieve
Insert into @MatchCount (FieldList, MatchCount)
Select "010203" as FieldList, Count(ID) as MatchCount
From SPF
Where SPF.Field1=1 and SPF.Field2 =1 and SPF.Field3 = 1
Return the @MatchCount resultset
dim sResults as string = string.empty
dim sField as string = string.empty
for each dr as datarow in ds.tables(1).ro ws
sResults = string.empty
for i = 1 to ctype(dr("Field List"),string). length step 2
sField = mid(dr("FieldLi st"),i,2)
if sResults.length = 0 then
sResults =
string.format(" Field{0}",ctytp e(ctype(sfield, integer),string ))
else
sResults = string.format(" {0},
Field{1}",sResu lts,ctytpe(ctyp e(sfield,intege r),string))
end if
next i
console.writeli ne string.format(" The match count for fields:{0} is
{1}",sresults,d r("MatchCount") )
next for
"onecorp" <on*****@commun ity.nospamwrote in message
news:58******** *************** ***********@mic rosoft.com...
>
I have run a sql suggestion and had the following queries,:
A)
(I made one small adjustment to your first suggestion in order to exclude
the Id column from the query, as follows:
If @Cols <'Id'
Set @qry='Select Count(*) From SPF Where (' + @qry + ')>1'
--Print @qry
Execute(@qry)
)
I executed the query on a table of 30 columns (adjusted the count as
necessary) using columns labelled 1, 2, and 3 . It returned a value of 34,
however, the answer should have been 3. Three is the number of times that
one
simultaneously appears in each of the aforementioned columns ie . I only
wish to count the number or times that '1' appears in the nominted columns
simultaneously, whether I am checking two columns at a time or three
columns
( or even 4 columns....whic h is why I thought that the query should be
built
in managed code(VB .net) using SQL CLR ?????).
B)When I tried to use a table with 38 columns , I received the following
error:
Msg 217, Level 16, State 1, Procedure spMyTest2, Line 45
Maximum stored procedure, function, trigger, or view nesting level
exceeded
(limit 32).
even after ensuring that I adjusted the count correctly....
C) This procedure appears to only return one value based on inputting the
paramters as indicated. For a table that contains 38 columns, there should
be
8436 values. How do I return a list of all the combinations, not just one?
.....Hence I thought managed code SQL CLR should be used. Does anyone have
any suggestions please ?
Any assistance would be appreciated.
Thank you
Onecorp
"onecorp" wrote:
>Hi PGC,
Thank you for your reply.
No the datatable cannot have a variable number of columns. There are a number of different datatables. The simplest has 27 columns, the most complex has 59 columns.
Regards
Onecorp
"PGC" wrote:
Hi onecorp,
I don't get this. Are you saying that the datatable can have a variable
number of columns? Can you provide the table definition? If the number
of
columns is going to change when you go looking for the data then maybe
they
should be rows in an other table instead.
PGC
"onecorp" <on*****@commun ity.nospamwrote in message
news:1D******** *************** ***********@mic rosoft.com... I have a SQL table comprised of 31 columns.
The first column is simply an id column, the next 30 columns are
labelled
[1],[2]...[30].
The numerical columns have a tinyint type and the data stored is
either 1
or
null.
I wish to count the number of times a one appears in one column
simultaneously with another column:
eg count the number of times 1 appears in column [1] and 1 also
appears in
column[15] in the same row:
Column [1] Column[15]
1 1 Count this
1 Don't count this
1 1 add 1 to the count
1 1 add 1 to the count
1 Don't count this
1 Don't count this
1 1 add 1 to the count
1 1 add 1 to the count,
etc.
The following has been suggested to me as a possible solution:
Imports MWFN
Partial Class MembersPages_My Page
Inherits System.Web.UI.P age
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim pairsAdapter As New MWFNTableAdapte rs.MWFNTableAda pter
Dim pairs As MWFN.MWFNDataTa ble
pairs = pairsAdapter.Ge tData
Dim myColumns As Data.DataColumn Collection = pairs.Columns
Dim columnA As Data.DataColumn
Dim columnB As Data.DataColumn
Dim num3 As Hashtable
For Each columnA In myColumns
If columnA.ColumnN ame <"Id" Then
For Each columnB In myColumns
If columnB.ColumnN ame <"Id" And columnB.Ordinal >
columnA.Ordinal Then
'if columnB's name doesn't equal Id and columnB's
position number is over columnA's, sum columnA and columnB
num3.Add(column A.ColumnName & "," &
columnB.ColumnN ame, pairs.Compute(" SUM(" & columnA.ColumnN ame & ") +
SUM( " &
columnB.ColumnN ame & ")", ""))
End If
Next
End If
Next
End Sub
End Class
I have used a dataset to obtain the columns from the database
datatable in
an effort to use a data access layer in my project. The dataset is
MWFN.
The above code produces the following:
Warning: num3 is used before it has been assigned a value.
And when the programme is run:
Expecting a single column argument with possible child qualifier.
At this point in time , the code only sums/counts two columns. I will
wish
to broaden that to sum/count 3 , 4 and possibly 5 columns, so the
code
needs
to be extensible. The number of columns will alos vary (probably from
27
to
59).
It doesn't matter if your suggestion is to use transact sql is a
stored
procedure before the data gets to the project, or use vb as per the
above
mentioned suggestion.
Any assistance would be appreciated.
Thank you
onecorp
Can anyone help point me in the right direction This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ravi Shankar |
last post by:
Hi all,
I have a calendar application( like Microsoft Outlook) writtn in
Java.Whenever an event is created, we can set SMS/EMAIL notification. Hence
when an event is created, I am storing that event info and notification time
into a database.Now the notification can be ranging from 5 minutes to say
one day.Hence I need to query the databse every 5 minutes and fetch the data
and do send the notification directly. I understand that such a...
|
by: Keith |
last post by:
I am fairly new to SQL so sorry if this is a really dumb question.
I have a small (still) SQL database, which I am trying to query from an ASP
page.
The field I am querying is of DATETIME data type, and is populated
automatically using the GetDate() function as a default value.
When I try and search on this field, using a date/time in the format
dd/mm/yyyy hh:mm:ss as the search criteria, it fails with the following
|
by: valexena |
last post by:
After a few minutes of querying the database my session disconnects
abruptly. Can somebody help me and tell why can be happening?
--
Posted via http://dbforums.com
|
by: Elliot Rodriguez |
last post by:
As I continue to read more about the benefits of database querying using
ADO.NET, I am having a more difficult time distinguishing what the best
approach to data retrieval is anymore.
When creating datasets in the Visual Studio.NET designer, Command objects
(Update, Insert, Delete) are automatically generated for you based off your
SelectCommand value. You then get the benefits of strong typing, which from
what I've seen so far are...
|
by: radicool |
last post by:
What is the User ID and Password for querying Follett's TextLink database.
I am using Adaptive Server Anywhere. If this is not the best group to
ask this, where would be?
| |
by: Greg |
last post by:
I am working on a project that will have about 500,000 records in an XML
document. This document will need to be queried with XPath, and records
will need to be updated. I was thinking about splitting up the XML into
several XML documents (perhaps 50,000 per document) to be more efficient but
this will make things a lot more complex because the searching needs to go
accross all 500,000 records. Can anyone point me to some best practices...
|
by: Shane |
last post by:
I wonder if someone has any ideas about the following.
I am currently producing some reports for a manufacturing company who work
with metal.
A finished part can contain multiple sub-parts to make up the finished part.
The sub-parts can also be made up of sub-parts and those sub-parts can also
be made up of sub-parts etc etc.
All parts are contained within the same table and I have a seperate table
|
by: roiavidan |
last post by:
Hi,
I'm having a bit of a problem with a small application I wrote in C#,
which uses an Access database (mdb file) for storing financial data.
After looking for a similiar topic and failing to find one, I'm posting
the question in hope some one of you guys out there will have the
answer for me...!
I'll start with what I have, then I'll continue to the problem itself.
|
by: sql_er |
last post by:
Guys,
I have an XML file which is 233MB in size. It was created by loading 6
tables from an sql server database into a dataset object and then
writing out the contents from this dataset into an XML file.
Once my application starts, I load this XML file into a DataSet object
using "ReadXML" function. This creates a dataset in memory with 6
tables.
|
by: RajSharma |
last post by:
Hi,
I am facing a problem regarding querying thru a large table having millions of rows.......
Its hanging in between while querying for all those rows
Can anybody suggest me a query regarding :
Querying the database everytime for next 100 records ( that means i need to set up a cursor) till the count of the table rows ends up(take 1 million rows e.g.)
The database is DB2
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |