|
that is give me error
Msg 8120, Level 16, State 1, Line 25
Column NumCustomers is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
how to solv it??
when i want to read something good just seat and type it
|
|
|
|
|
Colin Angus Mackay wrote: SELECT Employer.Name, CustomerCount.NumCustomersFROM EmployerINNER JOIN (SELECT IdEmployer, COUNT(*) AS NumCustomers FROM CustomerEmployer) AS CustomerCountON CustomerCount.IdEmployer = Employer.IdEmployer
You need to add ORDER BY CustomerCount.NumCustomers DESC to give you the maximum first. To get only the maximum, use SELECT TOP 1 Employer.Name, etc.
SELECT TOP 1 Employer.[Name], CustomerCount.NumCustomers
FROM Employer INNER JOIN (SELECT IdEmployer, COUNT(*) AS NumCustomers
FROM CustomerEmployer
GROUP BY IdEmployer) AS CustomerCount
ON CustomerCount.IdEmployer = Employer.IdEmployer
ORDER BY CustomerCount.NumCustomers DESC
Ian
-- modified at 9:26 Thursday 17th August, 2006
|
|
|
|
|
Thank you very much.That is what i need.This code is great.
when i want to read something good just seat and type it
|
|
|
|
|
can anyone pls say in what kind of a scenario can i go for System.Data.Oledb and System.Data.Odbc. Is there any difference in their performance. will it suit well for Oracle.
-----------------------------------------------------------------
where there is a will there is a way
|
|
|
|
|
There is a specific Oracle provider that you can use. You should use the most specific provider for your database rather than one of the generic providers such as Odbc or OleDb
|
|
|
|
|
Hi guys,
Good Day!
My back-end in my system is MS SQL SERVER, the major scenerios here are, it performs weekly autoupdate for the database and the data is so huge.. then, evrytime its updating the transaction log is occupying more space in the drive and encounters error if i set it to restrict file growth or in uncheck automatically file growth (it says that i need to set more size for the transaction logs or else it will not perform)..
My problem here is how can i delete the tranasaction logs automatically or limit the size without encounter the error everytime i update the database, since my system does not need that?
Hope your response, guys... Thank you in advance....
regards,
JayR
|
|
|
|
|
Is your DB set to SIMPLE recovery model?
Do you have AUTO_SHRINK set ON?
Steve
|
|
|
|
|
You need to understand what the transaction log is and what it's used for. See this comment[^] and this comment[^] for details.
I ought to turn those into an article.
|
|
|
|
|
I have a table that has currency exchange rates as below
CCY EX_RATE RATE_DT
---- ------- -------
AED 1.1 7/31/06
AED 1.0 6/30/06
AED 1.5 5/31/06
What that means is that the exchange rate was 1.5 from 5/31 to 6/30 and is at 7/31 till eternity. What I want is the output to look like this
CCY EX_RATE START_DT END_DT
---- ------- -------- ------
AED 1.1 7/31/06 (NULL)
AED 1.0 6/30/06 7/31/06
AED 1.5 5/31/06 6/30/06
I think an self-join will give me the correct data but i am getting excessive rows when i do a join.
|
|
|
|
|
Asad,
This should work.
Select CCY, EX_RATE, MIN(RATE_DT) as START_DT, MAX(RATE_DT) as END_DT
From your_currency_table
Group by CCY, EX_RATE
Farhan Noor Qureshi
|
|
|
|
|
Thanks for your reply but that doesnt work. If I have this data
CCY EX_RATE RATE_DT
---- ------- -------
AED 1.1 7/31/06
AED 1.0 6/30/06
AED 1.5 5/31/06
It will return something like
CCY EX_RATE START_DT END_DT
---- ------- ------- ------
AED 1.1 7/31/06 7/31/06
AED 1.0 6/30/06 6/30/06
AED 1.5 5/31/06 5/31/06
I want it to give me ranges like
CCY EX_RATE START_DT END_DT
---- ------- -------- ------
AED 1.1 7/31/06 (NULL)
AED 1.0 6/30/06 7/31/06
AED 1.5 5/31/06 6/30/06
|
|
|
|
|
select ccy,ex_rate,rate_dt as start_dt,(select top 1 cur2.rate_dt from tblcurrencyrate cur2 where cur.ccy = cur2.ccy and cur2.rate_dt > cur.rate_dt order by cur2.rate_dt) as end_dt from tblcurrencyrate cur
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
I'm still getting the hang of this new tool and for the life of me, I can't remember how to add SQL procedures in the Stored Procedures folder. It keeps saving them as SQL files, but storing them as files. Man I miss the old look and feel. I finally got used to that one.
"In this house, we obey the laws of thermodynamics!" - Homer Simpson
Web - Blog - RSS - Math - LinkedIn
|
|
|
|
|
You have to run the CREATE PROCEDURE sp_XYZ query for the procedure to be created. F5 usually works for me.
-- modified at 18:33 Tuesday 15th August, 2006
Farhan Noor Qureshi
|
|
|
|
|
D'oh! Thanks. I was always removing that CREATE function since I was copying it from my old procedures. That kinda sucks the way they did it. I much prefer the older method. F5 doesn't create it if CREATE isn't there.
"I know which side I want to win regardless of how many wrongs they have to commit to achieve it." - Stan Shannon
Web - Blog - RSS - Math - LinkedIn
|
|
|
|
|
i´m trying to select the names of dimension members from a data cube. when working under sql server 2000, i´m using this mdx query select distinct [Projekt_Owner].[Projekt Owner] from datacube and it´s working just fine... but when i´m trying to do the same under sql server 2005, i always get the same error:Error (Data mining): Either the user, does not have permission to access the referenced mining model or the object does not exist. can anyone help my with this?
cellardoor
|
|
|
|
|
using VS2005;
Can someone please help me out with this:
I have a datatable that contains several columns including "ReportDate" and "Amount". What I want to be able to do is retrieve the value from the datatable in the "Amount" column when all I know is the same rows "ReportDate" value. The "ReportDate" column is DateTime and the "Amount" column is Decimal. I know how to get this direct from the database table but not the corresponding datatable.
As part of the above answer, how do you pass a variable to the Select statement of a datatable lookup. I assume you can't use the same method of passing variables/paramaters to a SQL Statement because I can't seem to be able to do that either!
Glen Harvy
|
|
|
|
|
You could use DataView over your DataTable by applying a filter and then query the value for the desired column, for e.g. "Where ReportDate = '1/1/2006'".
Farhan Noor Qureshi
|
|
|
|
|
Hello:
Now i want to bulk insert a dataset into an excel file, is there any good method?Thanks in advance!
Plus: i am wodering the method of firstly store the datatable in sql sever,then use dts. but i think it seems a little redundant and time-wasting.
|
|
|
|
|
I don't know how do it from TSQL but here is how I have done it form C++
CString str;
str.Format("SELECT * INTO [Excel 8.0;DATABASE=%s].[%s] FROM [%s]", ExcelFile, Worksheet, Table);
pConn->Execute(str.AllocSysString(), NULL, adExecuteNoRecords);
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
Where is it?
--
-= Proudly Made on Earth =-
|
|
|
|
|
IIRC, it is in the Server Management Studio.
That's no moon, it's a space station. - Obi-wan KenobiLast modified: Monday, August 14, 2006 2:29:30 PM --
|
|
|
|
|
There isn't one, SQL Server Management Studio replaces both Enterprise Manager and Query Analyzer.
If you only have SQL Server 2005 Express Edition, you have to download Management Studio Express separately. Otherwise you have to use Server Explorer in VS, or the sqlcmd utility (a replacement for isql and osql, although osql is still supplied).
|
|
|
|
|
I have the developer's edition of the server. I couldn't find such a tool on the DVD. Is the management studio a "real server" only thing? I suppose that if you can download it for SQL Server Express, there ought to be one available for the developer's edition. I'll check it out. Thanks!
--
Hey, TiVo! Suggest this!
|
|
|
|
|
There's a checkbox for it in the installer: select 'Workstation components'. It's not checked by default.
|
|
|
|