Verifying A Table's Column Count Across Servers?

Jan 31, 2005

Hi folks!

The boss has decided that the data from a table we have on one database (containing daily data) needs to be copied to a "history" table on a different database, on a different server.

The transfer will probably be done with a scheduled stored procedure, and all columns will be transferred EXCEPT for two columns in the source table, which are not present in the destination table. This means instead of an "INSERT Dest SELECT * FROM Source" I have to do an "INSERT Dest SELECT yada,yada,yada... FROM Source" in order to disregard the columns we don't care about. NO problem.

I was thinking (you should smell trouble - and sawdust burning at this point) that this leaves us open to a punch below the belt later when a new column is added to the Source table, since we are using a definitive list of columns to move rather than a *, and the new column could be added without the otherwise system-generated, *-sponsored "gentle reminder" that it also needs to be added to the Dest table. I'm not as convinced as The Boss that "Oh, I'm sure we'll remember to add it to the history table when that happens" :lol:

So, long story shorter (nah...too late for that) - I figure I can write a check at each day's historical transfer on the count of columns in one table verses the other, and send an email or fail the job if the count doesn't make sense.

For example, if the Source table has 34 columns, since we don't care about two of them, the Dest table should have 32 columns, if things are still in synch. OK, I think (insert burning sawdust smell here), I can use a SysObjects thang to count rows. BOL points out INFORMATION_SCHEMA.COLUMNS as a possibility.

Here is the code I think (sawdust) can be used:select ((select count(*) from SourceDb.INFORMATION_SCHEMA.columns
where table_name = 'Source') - (select count(*) from HISTSERVER.DestDb.INFORMATION_SCHEMA.columns
where table_name = 'Dest')) as ColumnDiff

Trouble is...this fails because apparently the INFORMATION_SCHEMA thang doesn't do well with remote servers.

Can anyone figure a way around this, or suggest an alternative? I'm still looking, but thought I'd also toss it out onto the board for your generous consideration.

Thanks - and can you BELIEVE the year is already 1/12th of the way OVER?!?!?!
Paul

View 4 Replies


ADVERTISEMENT

Verifying Column Definitions Across Tables And Views

Aug 22, 2015

Let me explain in simplified terms. We have an ETL process:

1) download data from the iSeries table Cust into SQL table Cust.
2) Tran_Cust is a view created FROM Cust
3) Copy from view Tran_Cust to table ods_Cust
4) v_ods_Cust is a view created from ods_Cust

I want to look for inconsistencies in the column definitions as a column moves from iSeries Cust, SQL Cust, view Tran_Cust, ods_Cust, view v_ods_Cust. The columns generally keep the same names except for v_ods_cust. Here a column like CustName will be created with a more meaningful column name - "CustName as 'Customer Name'.

We have hundreds of tables and we have column definition inconsistences where the host changed their column defintion and we made no changes on the SQL side. Or someone made a SQL column change in one table, but not both tables and the views were not dropped and recreated.

I have the list of tables. Think that I can put together some tsql to loop through the list of tables and create a new table based on the iSeries definition, then compare columns defintion across all the tables and views - except for the v_ods. THis is where columns are given new names - such as "CustName as 'Customer Name'". Need the actual view definition to find that CustName is 'Customer Name' and then compare the definition of ods_Cust.CustName to v_ods_Cust.[Customer Name]

How can I find the view definiton of say v_ods_Cust, seperate out the source column names (CustName) and destination column names (Customer Name) so that I can compare the source column names to another table and fine the differences?

View 3 Replies View Related

Verifying URL's In Table

Mar 30, 2008

Does anyone have a routine that can verify URL's in a database table.  I have a table with several thousand website addresses and I would like a way to check and see which ones resolve and which return Page Not Found error.  I quess my question is how do you interrogate a URL and what do you look for coming back?  Novitiate for many I am sure but not for me.
Thank you.

View 3 Replies View Related

Count Changes On One Column In A Table

Oct 26, 2007

I've a nub question that someone probably has the fast answere too.

How do I count the number a columnvalue in a table has changed? I was starting to write a stupied cursor but there has to be a much smarter way.

I've a case where I need to count the number of times the salary in a table for individual employees changes.

Thanks in advance!

View 2 Replies View Related

Add SQL Count Column To Existing Table

Apr 22, 2008

I have a table for blog comments I want to add a column that counts the number of comments for each article.
existing table looks like this:
CommentID
ArticleID (FK)
commentAuthor
authorEmail
comment
commentDate (getDate())
I would like to add a column that counts the number of total comments for each article.This will give me what I want using the VS query tool:
"SELECT COUNT(comment) AS Expr1 FROM UserComments WHERE (articleid = @articleid)"
But can I add that to the table somehow so it does it automagically???

View 5 Replies View Related

How To Count Particular Text (/) From A Column In A Table?

Jun 16, 2008

I m using SQL Server 2000.
I have Tabel named Topic and have a column name lineage.  lineage has data like following:
//////546707//546707//546707/43213/
Now I want to get records who has only one "/" in it's crreponding lineage column.
 Can somone tell me how to do that in SQL Server 2000?
Thanks
Khushbu

View 2 Replies View Related

Updating A Column With A Count From Another Table?

May 18, 2014

My goal is to with one update statement, fill TABLE1.counter (currently empty) with the total count of TABLE2.e# (employee). Also, if TABLE1.e# isn't in TABLE2.e# then it sets it to "0" (TABLE1.e# 8 and 9 should have a counter of 0) This is for sqlplus.

e.g. TABLE2:

e#
--
1
2
3
4
5
5
6
7
7
1
2
3
4
5
UPDATE TABLE1
SET counter = (
SELECT COUNT(TABLE2.e#)
FROM TABLE2 INNER JOIN TABLE1 ON (TABLE2.e# = TABLE1.e#)
GROUP BY TABLE2.e#);

--^Doesn't work

so my TABLE1 should be:

e# counter
-----------
1 .. 2
2 .. 2
3 .. 2
4 .. 2
5 .. 3
6 .. 1
7 .. 2
8 .. 0
9 .. 0

(The .. is just spacing to show the table here)

View 1 Replies View Related

How To Get Maximum Count Of A Column In A Table.

Dec 6, 2007

i have a table with productID and OrderID. For ech product there are orders.
So for each productID there are lot Of OrderID's are present.
My data like

ProductID OrderID

1 12012
1 12447
1 12478
2 24154
2 21457 etc.......

so, i need to get the maximum count for a product.

i can do by using Temporary tables. but i need without using temporary tables.

please help me out.

thanks
-Praveen.

View 12 Replies View Related

How Count Column In Pivot Table- And Add Result Row

Jan 20, 2008

how count column in pivot table- and add result row
i need to calculate each column
for example
day1 day2 day3 day4 day5
-------------------------------------------------------------------------
1 2 1 2 3
1 2 3 2 2
2 3 2 1 2
2 3 0 0 0
-----------------------------------------------------------new result row
ok ok 1|2|3 1 3

i need to check each column
if i have twice each number
if not show the missing number
TNX




Code Block
DECLARE @Employee TABLE (ID INT, Date SMALLDATETIME, ShiftID TINYINT)
DECLARE @WantedDate SMALLDATETIME, -- Should be a parameter for SP
@BaseDate SMALLDATETIME,
@NumDays TINYINT
SELECT @WantedDate = '20080301', -- User supplied parameter value
@BaseDate = DATEADD(MONTH, DATEDIFF(MONTH, '19000101', @WantedDate), '19000101'),
@NumDays = DATEDIFF(DAY, @BaseDate, DATEADD(MONTH, 1, @BaseDate))

IF @Numdays > 28
BEGIN
SELECT p.ID,
p.[1] , p.[2],p.[3], p.[4], p.[5], p.[6], p.[7], p.[8], p.[9], p.[10], p.[11],
p.[12], p.[13], p.[14], p.[15], p.[16], p.[17], p.[18], p.[19], p.[20], p.[21],
p.[22], p.[23], p.[24], p.[25], p.[26], p.[27], p.[28], p.[29], p.[30], p.[31]
FROM (
SELECT ID,
DATEPART(DAY, Date) AS theDay,
ShiftID
FROM v_Employee
WHERE Date >= @BaseDate
AND Date < DATEADD(MONTH, 1, @BaseDate)
) AS y
PIVOT (
min(y.ShiftID) FOR y.theDay IN ([1], [2], [3], [4], [5], [6], [7],[8] , [9], [10], [11],
[12], [13], [14], [15], [16], [17], [18], [19], [20], [21],
[22], [23], [24], [25], [26], [27], [28], [29], [30], [31])
) AS p
END

View 12 Replies View Related

Trigger To Update Table Based On COUNT Of Column

Sep 26, 2007

Hello again,

I'm hoping someone can help with with a task I've been given. I need to write a trigger which will act effectively as a method of automatically distributing of incoming call ticket records. See DDL below for creation of the Assignment table, which holds information on the call ticket workload.





Code Snippet
CREATE TABLE #Assignment
(CallID INT IDENTITY(1500,1) PRIMARY KEY,
AssignmentGroup VARCHAR(25),
Assignee VARCHAR(25)
)
GO
INSERT #Assignment (AssignmentGroup, Assignee)
VALUES ('Service Desk', 'Jim Smith')
INSERT #Assignment (AssignmentGroup, Assignee)
VALUES ('PC Support', 'Donald Duck')
INSERT #Assignment (AssignmentGroup, Assignee)
VALUES ('Service Desk', 'Joe Bloggs')
INSERT #Assignment (AssignmentGroup, Assignee)
VALUES ('Service Desk', 'Joe Bloggs')
INSERT #Assignment (AssignmentGroup, Assignee)
VALUES ('Service Desk', 'Joe Bloggs')
INSERT #Assignment (AssignmentGroup, Assignee)
VALUES ('PC Support', 'Donald Duck')
INSERT #Assignment (AssignmentGroup, Assignee)
VALUES ('PC Support', 'Mickey Mouse')

GO

SELECT COUNT(CallID) AS [Total Calls], AssignmentGroup, Assignee
FROM #Assignment
GROUP BY AssignmentGroup, Assignee
ORDER BY COUNT(CallID) DESC , AssignmentGroup, Assignee






What I need to do is write a trigger for on INSERT to automatically update the Assignee column with the name of the person who currently has the least active calls. For example, using the data above, the next PC Support call will go to Mickey Mouse, and the next two Service Desk calls will go to Jim Smith.


So, the logic for the trigger would be

UPDATE #Assignment
SET Assignee = (SELECT Assignee FROM #Assignment WHERE COUNT(CallID) = MIN(COUNT(CallID))


But that's only the logic, and obviously it doesn't work with the syntax being nothing like correct.

Does any one have an idea or pointers as to how I should go about this?

Grateful for any advice, thanks
matt

View 5 Replies View Related

Dynamic View - Add A Column To Display Running Count In Table

Jul 22, 2014

I have a view created from only one table.

VW_Stats ( Tab_Name,Load_Status,User,....)

Tab_Name & Load_Status columns provides the information about Name of table and status of data getting loaded to this table.

To this I would like to add a column to display the running count in the table, I mean how many records so far loaded, as below the recordCount coming from the same table tbl_collection

Table_name Load_Status RecordCount User...
tbl_collection Running 1244 XYZ

View 7 Replies View Related

In SQL 2000 Can I Use Count() To Count A Column?

Nov 26, 2007

I use SQL 2000
I have a Column named Bool , the value in this Column is  0ã€?0ã€?1ã€?1ã€?1
I no I can use Count() to count this column ,the result would be "5"
but what I need is  "2" and "3" and then I will show "2" and "3" in my DataGrid
as the True is  2 and False is 3
the Query will have some limited by a Where Query.. but first i need to know .. how to have 2 result count
could it be done by Count()? please help.  
thank you very much
 

View 5 Replies View Related

Verifying A Backup

Jun 27, 2006

Hey Folks...
Very new to SQL Server. I've inherited numorous SQL Servers and wanted to know how I can tell if a backup is scheduled and how I can tell if it completed successfully? Thanks in advance....

Mike D.

View 5 Replies View Related

Verifying Authentication

Nov 14, 2005

Hi guys,

View 4 Replies View Related

Table Row Count + Index Row Count

Jul 23, 2005

SQL 2000I have a table with 5,100,000 rows.The table has three indices.The PK is a clustered index and has 5,000,000 rows - no otherconstraints.The second index has a unique constraint and has 4,950,000 rows.The third index has no constraints and has 4,950,000 rows.Why the row count difference ?Thanks,Me.

View 5 Replies View Related

Verifying Entry Is Not In DB B4 Inserting

Jun 4, 2007

How do i do that... in sch lab, the lecturer said:    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click        Try            SqlDataSource2.SelectParameters("Title").DefaultValue = txtProductTitle.Text            GridView1.DataBind()            If GridView1.Rows.Count > 0 Then //if no repeated                 Label1.Text = "Existing Record Found. Please enter another Software."            Else                'SqlDataSource1.Insert()                'Label1.Text = txtProductTitle.Text & " successfully added to the database."            End If        Catch ex As Exception            Label1.ForeColor = Drawing.Color.Red            Label1.Text = "An error occured!" & ControlChars.NewLine & ControlChars.NewLine & _            ex.Message.ToString()        End Try    End Sub but its not working for me... the GridView1.Rows.Count is always 0, if there is a repeat, it should be > 0 

View 4 Replies View Related

Programatically Verifying SQL Syntax

Nov 24, 2004

OK, so I'm working on a project that requires the dynamic generation of SQL statements. Now in Visual Studio .NET I'm sure many of you have used that wonderful visual database tool that allows you to magically "verify sql syntax" at the click of a button. It takes a query that looks like this:

"SELECT A.AFFID, A.UserName, A.Pass, A.FirstName, A.LastName, A.Company, A.Street, A.City, A.State, A.ZIP, A.Country, A.phone, P.EMail, A.RecieveEMail, A.SSN, A.JoinDate, A.AffType, P.ProductId, P.BuyerId FROM Affiliates A, Purchases P WHERE (ProductId > 0) ORDER BY 1"

and transforms it into something that looks like this:

"SELECT A.AFFID, A.UserName, A.Pass, A.FirstName, A.LastName, A.Company, A.Street, A.City, A.State, A.ZIP, A.Country, A.phone, P.Email, A.RecieveEMail, A.SSN, A.JoinDate, A.AffType, P.ProductID, P.BuyerID
FROM Affiliates A CROSS JOIN Purchases P
WHERE (P.ProductID > 0)
ORDER BY A.AFFID"

My question is: is there anything in the .NET platform that would allow me to achieve the same kind of result programatically (i.e. transform standard sql to tsql syntax and verify the syntax of the query at run time)?

Any help would be appreciated! Cheers.

View 2 Replies View Related

Need Help In Verifying User Login

Feb 19, 2005

To: All,

Hi, well thanks for reading this thread. Anyway I got a problem where i can't accurately verify whether a user had successfully login to my application.

I got a database to store the user name and password. So whenever a user login, i would use a while loop to read all the user name and password, and an if statement to verify whether the user's name and password matches to the ones stored in the database. This method doesn't work when there are multiple records in my database, because the if statement would compare the user given name and password with all the user name and password in the database. Hence resulting a mismatch.

Well I really hope that you understand what my problem is, really need help with this problem as I'm really clueless. Can somebody please help me, please teach me how to rectify this problem?

Well i think the core problem would be to compare the user name and password with the records in the database one at a time, and once it is found, stop comparing and allow user to enter site.

Yup I think that's all, sorry for the lengthy thread. Anyway thanks a million and have a nice day.

From: iaciz

View 2 Replies View Related

Verifying SQL Server Licensing

Aug 8, 2006

How do I tell what SQL licensing option (processor, device CALS or user CALS) was taken when the server was installed? I have taken over a SQL 2005 server and I would like to check how many CALS (if any) it is licensed for.

View 2 Replies View Related

Verifying Ms Sql Server Desktop Installation

Feb 20, 2005

I am trying to use msde for the startup kits. but i cannot connect to it. How can I do a simple test to verify it is installed and that I can log into the db?

Thanks
Ron

View 1 Replies View Related

Verifying That A Task Completed Successfully

Oct 4, 1999

How can a tell if a tak completed succesfully from a stored procedure?

I have a task which is executed from a stored procedure. The sp_runtask only returns whether the task started successfully. How can I tell if it completed successfully?


Thanks

View 3 Replies View Related

Verifying Connection To 3rd Party Application

Jul 23, 2005

Is there a way that SQL can automatically look at each users'connection and make sure it is still connected through the third partyapplication? The problem is that when a connection to this applicationis not terminated properly, the SQL server is not notified of thedisconnect and the user cannot log back into the application until allthe processes are completed and the original session terminated.Thank you.

View 1 Replies View Related

Reporting Services :: Count Values In A Column Based Upon Distinct Values In Another Column In SharePoint List

Sep 7, 2015

We have SharePoint list which has, say, two columns. Column A and Column B.

Column A can have three values - red, blue & green.

Column B can have four values - pen, marker, pencil & highlighter.

A typical view of list can be:

Column A - Column B
red  - pen
red - pencil
red - highlighter
blue - marker
blue - pencil
green - pen
green - highlighter
red  - pen
blue - pencil
blue - highlighter
blue - pencil

We are looking to create a report from SharePoint List using SSRS which has following view:

                    red     blue   green
    pen            2       0      1
    marker       0       1      0
    pencil          1       3      0
    highlighter  1       1      1 

We tried Sum but not able to display in single row.

View 2 Replies View Related

Stored Procedure For Verifying Data Existence

Jun 26, 2006

Hello All,
I'm trying to develop a stored procedure that would do one of TWO things:
1.  Return a 'status' that a value does not exist, if I were to provide the parameter via an ASP.NET2.0 page
2.  If it does exists, to return the row data associated with that value (id number)
The stored procedure would search a SQL Server table within it self first.  It that fails it would look at an Oracle table (work order table).  And if that fails to return a 'row' to look through another Oracle table (work request table).  If that doesn't occur, then it would throw the result as described in #2.
If the result exists in one of the TWO Oracle tables it would then insert that row into the first SQL Server table that the stored procedure searched through AND would return the row set to the ASP.NET page.
While all this is happening, I was hoping to get some insight as to how to create a "Please Wait..." feedback and then moving to the final result.
Looking forward to the wise words of the many on this forum, as I have experienced in the past!  :)
 

View 2 Replies View Related

Is There A Tool For Verifying Data After Merged Access To Mssqlserver

Dec 24, 2007

hi, all.I want to verify data merged from access in sqlserver.but it has toomany records .so i need a tooldo this.someone maybe has it.thanks

View 1 Replies View Related

Verifying MergeSynchronizationAgent No Longer Requires STA Threading Model

Dec 22, 2006

I've seen a few posts in the MSDN documentation (see links below) stating that the MergeSynchronizationAgent no longer requires the STA threading model in SQL Server 2005 SP1. However, I'm still receiving the following exception message in my synchronization code (where it attempts to access the SynchronizationAgent property):


The MergeSynchronizationAgent class must be instantiated on a Single-Threaded Apartment (STA) thread.

I have Service Pack 1 for SQL Server 2005 installed on both my server as well as my local client (the client is running SQL Server 2005 Express). How can I verify the correct files are there (e.g. are the some specific date/time values for the RMO/COM objects?

Here's the list of MSDN links mentioned above:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=326837&SiteID=1
http://msdn2.microsoft.com/en-us/library/ms146869.aspx
http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.replication.mergesynchronizationagent.aspx
http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.replication.mergepullsubscription.synchronizationagent.aspx

View 3 Replies View Related

Matrix Column Subtotal W/incorrect Scope On Some Servers

Oct 1, 2007



This works correctly in the Business Intelligence Dev Studio tool and on one of our servers, but fails on the other two servers. The two servers that do not work are current on their patches.

When a matrix has multiple rows and multiple columns, the highest level column subtotal is in the wrong scope. Say we have three row groups (r1, r2, and r3) and two column groups (c1, c2). All five groups have subtotals enabled. We can check the scope of every cell by setting the expression of our Detail/Value textbox like so:

=IIf(InScope("r1"),"r1, ","") &
IIf(InScope("r2"),"r2, ","") &
IIf(InScope("r3"),"r3, ","") &
IIf(InScope("c1"),"c1, ","") &
IIf(InScope("c2"),"c2, ","")

When run, the lowest level "detail" boxes should be in the scope of all groups: "r1, r2, r3, c1, c2,". The subtotal of r3 is in scope for everything except for itself (r1, r2, c1, c2,), and so on (see "Good server" screenshot).

This is how it should work, and it does work this way in the design tool and our one (development) server. The other two servers (which are, unfortunately, the Test and Production servers) have a problem: the subtotal of c1 (the column running furthest along the right) is ONLY r1. Always. Which results in some ridiculously large subtotals for detail rows.

We've tested this with various combinations of 2 - 5 column groups and 2 - 5 row groups and found no difference; the problem still hits the furthest right column in the exact same way. We've changed everything we can think of, and tried multiple reports built from scratch and using different data sources, but the results are still consistent.

Any ideas, explanations, or suggestions would be much appreciated.

Screenshots:
Matrix design: http://farm2.static.flickr.com/1010/1469081648_bc3cafe3dc_o.jpg
Good server: http://farm2.static.flickr.com/1055/1469081658_df8da1c261_o.jpg
Bad server: http://farm2.static.flickr.com/1058/1469081664_c56bc57c1a_o.jpg

View 14 Replies View Related

How To Count Column ?

Jan 22, 2008

HistoryLog Table

MainIndex

Sales

Date

1
John

Jan-05-1999

2
John

Jan-07-1999

3

Liz

Jan-08-1999

4
Yumi

Jan-08-1999


HistoryLogDetail Table

DetailIndex
MainIndex 

Date

1
1

Jan-05-1999

2
1
Jan-07-1999

3
2

Jan-08-1999

4
3

Jan-08-1999

select * from HistoryLog  I will got a return result with Mainindex ã€?Salesã€?Date 3 kinds of columns Data , If I need to add one column by myself let the result like below Mainindex ã€?Salesã€?Dateã€?Total the Total's value is from  count(MainIndex) of  HistoryLogDetail Table , result will look like below MainIndex   Sales         Date                Total1                  John         
Jan-05-1999      2       →(because this record's index 1 exist in HistoryLogDetail Table twice so the total is 2)2                  John         
Jan-07-1999      1      →(because this record's index 1 exist in HistoryLogDetail Table twice so the total is 1)3                   Liz          
Jan-08-1999       14                   Yumi       
Jan-08-1999       0 I trid wirte a code to got the total column but what I got is like thisMainIndex   Sales         Date                Total
1                  John         
Jan-05-1999      4
2                  John         
Jan-07-1999      43                   Liz          
Jan-08-1999       4
4                   Yumi       
Jan-08-1999       4 what the columns of Total shows is .. how many record are in  HistoryLogDetail Table but that's not I need ..can you help?thank you very much  

View 7 Replies View Related

2nd Count Column

Oct 29, 2007

Hey there,

I am new to SQL so please bear with me. I was wondering how to create a new column that counts the EntityId COUNT(CdsQuotes.EntityId) and puts it into a seperate column.

What I am trying to achieve is a count of entity IDs from one table and a count of entity IDs from another table - but the 2nd count must be from the first counts results (hope this makes sense).

So it returns a count from table 1 and then a corresponding count from table 2 (based on table 1 entityIDs)

Any ideas?

SELECT

Entity.EntityName,
SuspectBond.EntityId,
COUNT(SuspectBond.EntityId) as "Suspect Bonds"

FROM SuspectBond

INNER JOIN Entity ON
SuspectBond.EntityID = Entity.EntityId

WHERE
SuspectBond.StatusId = 1

GROUP BY
SuspectBond.EntityId,
Entity.EntityName

ORDER BY
COUNT(SuspectBond.EntityId) DESC

View 6 Replies View Related

How To Get The Column Count

May 6, 2008

hi,

I have a table as below

id col2 col3 col4 col5 col6 col7
1 2 2 2 2 3 4
2 3 6 2 2 2 5
3 2 3 4 2 2 6
4 3 2 2 2 9 8
5 2 3 4 6 2 2


I want to know the number of columns which is having the value 2, in each row

can anyone help?

View 2 Replies View Related

Inserted Rows Count From SSIS Not Like Table Rows Count

Jun 25, 2007

Hi all



i using lookup error output to insert rows into table

Rows count rows has been inserted on the table 59,123,019 mill

table rows count 6,878,110 mill ............................



any ideas

View 6 Replies View Related

Update Count Column

Apr 24, 2008

Hi I have added a new column to my table, i need to run a query and update this colmn with a count, so like

i = 1

loop

update table
set column = i
where column = 113

i=i+1

loop

just not sure what the sql syntax is?

View 20 Replies View Related

Return Column Name And Count

Nov 3, 2013

I'm starting to use SQL 2008 recently, and I'm just having trouble with the following problem:

The following query:

SELECT t_Category.Name as [Category]
FROM t_Assets, t_Category, t_Priority, t_Location, t_User_Assets
WHERE t_Assets.Asset_ID = t_User_Assets.Asset_ID
AND t_Category.Category_ID = t_User_Assets.Category_ID
AND t_Priority.Priority_ID = t_User_Assets.Priority_ID
AND t_Location.Location_ID = t_User_Assets.Location_ID

Returns this result:

Category
BMS
BMS
Water
BMS
BMS
Air

And the following query:

SELECT COUNT(t_Category.Category_ID) AS AssetQty
FROM t_Assets, t_Category, t_Priority, t_Location, t_User_Assets
WHERE t_Assets.Asset_ID = t_User_Assets.Asset_ID
AND t_Category.Category_ID = t_User_Assets.Category_ID
AND t_Priority.Priority_ID = t_User_Assets.Priority_ID
AND t_Location.Location_ID = t_User_Assets.Location_ID
GROUP BY t_Category.Category_ID

Returns this result:

AssetQty
4
1
1

I need to have both of those results returned, as a single result. Such as:

Category AssetQty

BMS 4
WATER 1
AIR 1

However, I'm not able to, due to the fact, that if I add the "t_Category.Category.Name" in the SELECT clause, it gives me the following error:

Column 't_Category.Name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

And if I try to use the "Name" as part of the count clause, it won't work, as text are not acceptable data types for aggregations.

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved