I am guessing "id" is really custid since you are looking for custid in it. Are you looking for the max(priority) for EACH customer (1) or the max(priority) for all customers in pending(2)? 1. Select * From( Select custid, max(priority)as Priority From customer Where status = 1 and custid <> '' Group by id ) as subtable Join pending On subtable.custid= pending.custid 2. SELECT * FROM Pending Join Customer on pending.custid = customer.custid WHERE priority = ( SELECT max(priority) FROM customer Join pending on customer.custid = pending.custid WHERE customer.custid <> '' and status = 1 ) Where pending.custid <> '' michanne
michanne
Posts
-
can anyone optimize this query -
running mysql_install_db on windowsI believe that instruction is for linux. Those db's should already be installed. Look for section 2.4.1 in the manual. michanne
-
MS SQL Server date formatLeft(Convert(char(6),getdate(),12),4) michanne
-
Month to date in SPIf you are interested in the last full month and need the last day - you run into problems with February. Try: declare @month char(10),@lastmonth datetime set @month = Convert(Char(6),getdate(),112)+'01' Print @month select @lastmonth = dateadd(m,-1,cast(@month as datetime)) print @lastmonth --First day of prior month select @lastmonth = dateadd(d,-1,cast(@month as datetime)) print @lastmonth --Last day of prior month Barbara
-
SQL Server 8.0 and 7.0You mean 2000 - is that 8.0? You can have them both installed on the same machine. I believe you want 7.0 to exist and then install 2000 as a new instance - but I not sure that is a requirement. Barbara
-
How to replace a string while retrieving data from an access database in ASP. NETSelect IIF([empname]='tt','mm',[empname)) as empname From employeetable; This will give you mm if the value of empname is 'tt'; otherwise it will give you empname. Hope that is what you are looking for :cool: Barbara
-
Using UDFs in a SELECToh - ok I see the problem. You can't use a variable in the FROM clause. You may need to put the function in place of @dates or use a derived set. Barbara
-
Using UDFs in a SELECTI suspect the problem is in the inner join statement. Try this: SELECT calc.* FROM @dates as fd INNER JOIN ( SELECT * FROM (dbo.calculation(fd.[date]))) as calc ON cc.[date] = fd.[date] Barbara :cool:
-
SP that support data PagingYou have a couple of choices, Take your pick :) http://www.sqlservercentral.com/columnists/glarsen/sequentialnumbering\_printversion.asp Barbara
-
Question for an expert Transact SQL GURU!Actually you can do it. :cool: What you are missing is the that it needs to be an nvarchar. this is from http://support.microsoft.com/default.aspx?scid=kb;EN-US;q262499 \CREATE PROCEDURE Myproc @parm varchar(10), @parm1OUT varchar(30) OUTPUT, @parm2OUT varchar(30) OUTPUT AS SELECT @parm1OUT='parm 1' + @parm SELECT @parm2OUT='parm 2' + @parm GO DECLARE @SQLString NVARCHAR(500) DECLARE @ParmDefinition NVARCHAR(500) DECLARE @parmIN VARCHAR(10) DECLARE @parmRET1 VARCHAR(30) DECLARE @parmRET2 VARCHAR(30) SET @parmIN=' returned' SET @SQLString=N'EXEC Myproc @parm, @parm1OUT OUTPUT, @parm2OUT OUTPUT' SET @ParmDefinition=N'@parm varchar(10), @parm1OUT varchar(30) OUTPUT, @parm2OUT varchar(30) OUTPUT' EXECUTE sp_executesql @SQLString, @ParmDefinition, @parm=@parmIN, @parm1OUT=@parmRET1 OUTPUT,@parm2OUT=@parmRET2 OUTPUT SELECT @parmRET1 AS "parameter 1", @parmRET2 AS "parameter 2" go drop procedure Myproc Barbara, MCP