Click here to Skip to main content
15,903,030 members
Home / Discussions / Database
   

Database

 
GeneralRe: In sql service reports Pin
member2714-Nov-08 20:18
member2714-Nov-08 20:18 
QuestionStored Procedure Error Pin
Syed Shahid Hussain14-Nov-08 1:40
Syed Shahid Hussain14-Nov-08 1:40 
AnswerRe: Stored Procedure Error PinPopular
neilarnold14-Nov-08 2:00
neilarnold14-Nov-08 2:00 
GeneralRe: Stored Procedure Error Pin
Syed Shahid Hussain14-Nov-08 2:34
Syed Shahid Hussain14-Nov-08 2:34 
GeneralRe: Stored Procedure Error Pin
Syed Shahid Hussain14-Nov-08 2:41
Syed Shahid Hussain14-Nov-08 2:41 
GeneralRe: Stored Procedure Error Pin
Jeremy Falcon14-Nov-08 6:21
professionalJeremy Falcon14-Nov-08 6:21 
QuestionProblem with SQL Where - using IF or CASE Pin
But_Im_a_Lady13-Nov-08 23:11
But_Im_a_Lady13-Nov-08 23:11 
AnswerRe: Problem with SQL Where - using IF or CASE Pin
Ben Fair14-Nov-08 3:14
Ben Fair14-Nov-08 3:14 
I've come across this situation as well and here is the equivalent of what I've had to do:

WHERE @SalesOrderID = case when @SalesOrderID > 0 then M.SalesOrderID else @SalesOrderID end
  AND M.DateTransactionDue BETWEEN '01/01/1900' AND @AllocationEndDate
  AND M.TransactionTypeID = 1


In the above, you kind of have to think of the SalesOrderID filter very differently of how we normally handle it. Essentially, we'll use the CASE statement to compare @SalesOrderID either to the Field M.SalesOrderID or to itself. Comparing it to itself is the situation where the value is not provided and we don't want to filter on it, but we have to put something there and that accomplishes it. Also, notice that the CASE statement is resolved to provide the right side of the equals, so this gives you the flexibility to determine what you want to compare against; it's a pretty handy technique. If you prefer not to have the CASE statement and are free to modify the SP, you could have the @SalesOrderID default to NULL and then use ISNULL() in the WHERE, like so:

WHERE ISNULL(@SalesOrderID, M.SalesOrderID) = M.SalesOrderID
  AND M.DateTransactionDue BETWEEN '01/01/1900' AND @AllocationEndDate
  AND M.TransactionTypeID = 1


In this situation, when @SalesOrderID is NULL, the ISNULL function will use the Field M.SalesOrderID's value for the left side of the equals, essentially toggling whether to compare M.SalesOrderID against @SalesOrderID or itself and mimicking the desired behavior that the condition be optional; this too is also a handy technique. It's more compact and accomplishes the same thing as the above WHERE clause as long as @SalesOrderID defaults to NULL.

Keep It Simple Stupid! (KISS)

GeneralRe: Problem with SQL Where - using IF or CASE Pin
But_Im_a_Lady14-Nov-08 3:53
But_Im_a_Lady14-Nov-08 3:53 
QuestionProblem with synonyms in SQL Server 2005 Pin
boabab13-Nov-08 20:59
boabab13-Nov-08 20:59 
AnswerRe: Problem with synonyms in SQL Server 2005 Pin
Wendelius14-Nov-08 7:37
mentorWendelius14-Nov-08 7:37 
QuestionHow to get the schema of results from a stored procedure Pin
gantww13-Nov-08 11:00
gantww13-Nov-08 11:00 
AnswerRe: How to get the schema of results from a stored procedure Pin
Mycroft Holmes13-Nov-08 15:46
professionalMycroft Holmes13-Nov-08 15:46 
GeneralRe: How to get the schema of results from a stored procedure Pin
gantww13-Nov-08 17:17
gantww13-Nov-08 17:17 
QuestionSQL Express 2005 Database Read-Only Problem Pin
Ahmad Safwat13-Nov-08 3:37
Ahmad Safwat13-Nov-08 3:37 
AnswerRe: SQL Express 2005 Database Read-Only Problem Pin
Wendelius13-Nov-08 4:52
mentorWendelius13-Nov-08 4:52 
GeneralRe: SQL Express 2005 Database Read-Only Problem Pin
Ahmad Safwat13-Nov-08 5:37
Ahmad Safwat13-Nov-08 5:37 
GeneralRe: SQL Express 2005 Database Read-Only Problem Pin
Wendelius13-Nov-08 6:53
mentorWendelius13-Nov-08 6:53 
GeneralRe: SQL Express 2005 Database Read-Only Problem Pin
Ahmad Safwat15-Nov-08 21:11
Ahmad Safwat15-Nov-08 21:11 
GeneralRe: SQL Express 2005 Database Read-Only Problem Pin
Wendelius15-Nov-08 21:38
mentorWendelius15-Nov-08 21:38 
GeneralRe: SQL Express 2005 Database Read-Only Problem Pin
Ahmad Safwat15-Nov-08 23:50
Ahmad Safwat15-Nov-08 23:50 
GeneralRe: SQL Express 2005 Database Read-Only Problem Pin
Wendelius15-Nov-08 23:57
mentorWendelius15-Nov-08 23:57 
AnswerRe: SQL Express 2005 Database Read-Only Problem Pin
Paul Conrad13-Nov-08 6:39
professionalPaul Conrad13-Nov-08 6:39 
Questioninsert into and varbinary Pin
swjam13-Nov-08 2:18
swjam13-Nov-08 2:18 
AnswerRe: insert into and varbinary Pin
Wendelius13-Nov-08 4:45
mentorWendelius13-Nov-08 4:45 

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.