Click here to Skip to main content
15,915,873 members
Home / Discussions / Database
   

Database

 
AnswerRe: Variable value in SQL Query Pin
R. Giskard Reventlov30-Jul-10 0:45
R. Giskard Reventlov30-Jul-10 0:45 
GeneralRe: Variable value in SQL Query Pin
T.RATHA KRISHNAN30-Jul-10 0:54
T.RATHA KRISHNAN30-Jul-10 0:54 
GeneralRe: Variable value in SQL Query Pin
R. Giskard Reventlov30-Jul-10 0:57
R. Giskard Reventlov30-Jul-10 0:57 
GeneralRe: Variable value in SQL Query [modified] Pin
T.RATHA KRISHNAN30-Jul-10 1:16
T.RATHA KRISHNAN30-Jul-10 1:16 
GeneralRe: Variable value in SQL Query Pin
R. Giskard Reventlov30-Jul-10 1:42
R. Giskard Reventlov30-Jul-10 1:42 
GeneralRe: Variable value in SQL Query Pin
J4amieC30-Jul-10 6:29
J4amieC30-Jul-10 6:29 
AnswerRe: Variable value in SQL Query Pin
PIEBALDconsult30-Jul-10 19:20
mvePIEBALDconsult30-Jul-10 19:20 
QuestionStored procedure not returning all the rows expected Pin
Steven J Jowett29-Jul-10 23:51
Steven J Jowett29-Jul-10 23:51 
below is the stored procedure I’m having problems with. Its purpose is to filter the results within a result set returned by the spGetTicketList stored procedure, which works as expected.
If I remove the entire WHERE cluse section from the stored procedure I get 458545 rows returned, likewise if I include the Ticket Number range filters.
If I then add the Date range filter I get 446726 rows returned and if I include all the range filters I get 415179 rows returned. I am not providing any values for the parameters, other than the default values.

With all the filters in place there is 43,366 rows missing.

Any ideas?

ALTER PROCEDURE [dbo].[spFilterTicketList] 
(
	@LowTicketNumber VarChar(MAX) = '',
	@HighTicketNumber VarChar(MAX) = 'zzzzzzzzzzzzzzzzzzzzz',
	@LowDate DateTime = null,
	@HighDate DateTime = null,
	@AccountNumber varchar(MAX) = '%',
	@AcccountName varchar(MAX) = '%',
	@ShortName varchar(MAX) = '%',
	@StoreId varchar(MAX) = '%',
	@RoundId varchar(MAX) = '%'
)
AS
BEGIN
	DECLARE @t1 as Table
	(
		Id bigint,
		[Ticket Number] varchar(50),
		[Account Number] varchar(50),
		[Account Name] varchar(120),
		[Short Name] varchar(50),
		[Store Id] varchar(50),
		[Date] DateTime,
		[Round Id] varchar(50),
		Source tinyint
	);
	
	INSERT @t1 EXEC spGetTicketList;
	
	IF(@LowDate IS NULL)
		BEGIN
			SET @LowDate = CAST('1753-01-01 00:00:00.000' As DATE);
		END
		
	IF(@HighDate IS NULL)
		BEGIN
			SET @HighDate = CAST('9999-12-31 23:59:59.997' As DATE);
		END
	
	SELECT Id, 
		ISNULL([Ticket Number], '') AS [Ticket Number] , 
		ISNULL([Account Number] , ' ') AS [Account Number],
		ISNULL([Account Name] , ' ') AS [Account Name],
		ISNULL([Short Name] , ' ') AS [Short Name],
		ISNULL([Store Id] , ' ') AS [Store Id],
		CAST(ISNULL([Date], CAST('1753-01-01 00:00:00.000' As DateTime)) As DateTime) AS [Date],
		ISNULL([Round Id] , ' ') AS [Round Id],
		[Source] 
		FROM @t1
	WHERE ([Ticket Number] >= @LowTicketNumber) 
			AND ([Ticket Number] <= @HighTicketNumber)
			AND (CAST([Date] AS DateTime) >= @LowDate) 
			AND (CAST([Date] AS DateTime) <= @HighDate) 
			AND ([Account Number] LIKE @AccountNumber)
			AND ([Account Name] LIKE @AcccountName)
			AND ([Short Name] LIKE @ShortName)
			AND ([Store Id] LIKE @StoreId)
			AND ([Round Id] LIKE @RoundId)
	ORDER BY [Date] ASC ;
END

Steve Jowett
-------------------------
Real Programmers don't need comments -- the code is obvious.

Questionmany fields linked to one Pin
Jassim Rahma29-Jul-10 12:14
Jassim Rahma29-Jul-10 12:14 
AnswerRe: many fields linked to one Pin
Mycroft Holmes29-Jul-10 14:42
professionalMycroft Holmes29-Jul-10 14:42 
QuestionDerived Columns in where clause Pin
SatyaKeerthi1528-Jul-10 21:25
SatyaKeerthi1528-Jul-10 21:25 
AnswerRe: Derived Columns in where clause Pin
Blue_Boy28-Jul-10 21:48
Blue_Boy28-Jul-10 21:48 
GeneralRe: Derived Columns in where clause Pin
SatyaKeerthi1528-Jul-10 22:33
SatyaKeerthi1528-Jul-10 22:33 
AnswerRe: Derived Columns in where clause Pin
Jörgen Andersson28-Jul-10 23:17
professionalJörgen Andersson28-Jul-10 23:17 
GeneralRe: Derived Columns in where clause Pin
Jörgen Andersson28-Jul-10 23:30
professionalJörgen Andersson28-Jul-10 23:30 
GeneralRe: Derived Columns in where clause Pin
SatyaKeerthi1528-Jul-10 23:32
SatyaKeerthi1528-Jul-10 23:32 
GeneralRe: Derived Columns in where clause Pin
Jörgen Andersson28-Jul-10 23:58
professionalJörgen Andersson28-Jul-10 23:58 
GeneralRe: Derived Columns in where clause Pin
SatyaKeerthi1529-Jul-10 0:25
SatyaKeerthi1529-Jul-10 0:25 
GeneralRe: Derived Columns in where clause Pin
Jörgen Andersson29-Jul-10 0:45
professionalJörgen Andersson29-Jul-10 0:45 
AnswerRe: Derived Columns in where clause Pin
Estys29-Jul-10 0:13
Estys29-Jul-10 0:13 
GeneralRe: Derived Columns in where clause Pin
SatyaKeerthi1529-Jul-10 0:29
SatyaKeerthi1529-Jul-10 0:29 
AnswerRe: Derived Columns in where clause [modified] Pin
Luc Pattyn29-Jul-10 0:55
sitebuilderLuc Pattyn29-Jul-10 0:55 
GeneralRe: Derived Columns in where clause Pin
SatyaKeerthi1529-Jul-10 1:03
SatyaKeerthi1529-Jul-10 1:03 
GeneralRe: Derived Columns in where clause Pin
Eddy Vluggen29-Jul-10 2:37
professionalEddy Vluggen29-Jul-10 2:37 
QuestionFailed to connect to server Pin
Alduin28-Jul-10 11:31
Alduin28-Jul-10 11:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.