Viewing 15 posts - 1,246 through 1,260 (of 1,494 total)
The logic for working out the above is:
1. Self join the table on status where one code is less than or equal to the other code:
SELECT T1.code AS MinCode
,T2.code AS...
March 16, 2007 at 7:24 am
The following is similar to Brian's code but should be more efficient. If you have more than 10000 rows you may be better off using cursors/temp tables.
SELECT MIN(D.MinCode) AS MinCode
,D.MaxCode
,D.status
FROM...
March 16, 2007 at 7:11 am
March 16, 2007 at 5:08 am
I was thinking along the lines of:
SELECT *
FROM Employee E
JOIN (
SELECT ROW_NUMBER() OVER(PARTITION BY B.EmployeeId ORDER BY B.BillId DESC) AS Row
,B.BillId
,B.BillAmount
,B.BillMonth
,B.EmployeeId
FROM EmployeeBill AS B
) D ON E.EmployeeId = D.EmployeeId
WHERE D.Row...
March 16, 2007 at 4:58 am
Try something like the following. The UPDLOCKs are important to avoid deadlocks.
UPDATE I
SET Status= 1
,@IdentPK = I.Identpk
FROM pIdent I
JOIN (
SELECT MAX(D1.IdentPK) AS IdentPK -- will ignore NULLs
FROM (
SELECT MIN(I1.IdentPK) AS...
March 15, 2007 at 9:46 am
I find your question confusing.
You are more likely to get appropriate help if sample data and expected results are provided.
Maybe you want something like:
DECLARE @EndDate smalldatetime
,@StartDate smalldatetime
SET @EndDate = CAST(CONVERT(varchar(6),...
March 13, 2007 at 12:15 pm
Try looking up ROW_NUMBER() OVER(PARTITION BY ... in BOL.
March 12, 2007 at 3:26 am
My solution does need some error handling. (sp_releaseapplock in CATCH block etc)
Also, it would probably be better to use the SP name plus the @HashedBasketId for the resource just in...
March 8, 2007 at 9:56 am
If this is part of the
http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=360&messageid=346291
thread:
1. I would put the index on the FK and let the optimizer work out whether to use a MERGE or LOOP join based...
March 8, 2007 at 7:59 am
Opps,
See you have already done that.
March 8, 2007 at 5:17 am
Consistent use of application locks helps in this sort of situation.
Try something like:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[ST_BASKET_INSERT]
@BasketId int OUTPUT
,@HashedBasketId varchar
March 8, 2007 at 5:15 am
I suspect the problem is that CREATE LOGIN does not accept a variable for the login_name so a variable will not work within sp_executesql. (I do not have access to SQL...
March 7, 2007 at 10:28 am
A BatchID could also be generated from a dummy IDENTITY table. Something like.
CREATE TABLE dbo.BatchIDs
(
BatchId int IDENTITY NOT NULL
)
GO
DECLARE @BatchID int
BEGIN TRAN
INSERT INTO dbo.BatchIDs DEFAULT VALUES
ROLLBACK
SELECT @BatchID = SCOPE_IDENTITY()
-- SELECT...
March 7, 2007 at 7:36 am
Get rid of Enumerations and have separate tables for States, Countries etc.
March 7, 2007 at 6:30 am
Maybe:
SELECT @result = DATEDIFF(day, MIN(StartDATE), MAX(EndDate))
FROM @MyTable
March 7, 2007 at 6:23 am
Viewing 15 posts - 1,246 through 1,260 (of 1,494 total)