SQL Server >> Sproc question *should be easy, hopefully*

by Weston Weems » Fri, 17 Sep 2004 03:16:54 GMT

I've got an existing stored proc that takes two params.

Currently the internal query looks like this...

SELECT *
FROM
Issues
WHERE
Project = @ProjectId
and
....

Anyway... I want to just leave out the line Project =
@projectid, if @projectId, and I dont know where to begin
with that. I know of If/Then syntax, but dont see how I
caould apply it here.

Thanks


SQL Server >> Sproc question *should be easy, hopefully*

by Tibor Karaszi » Fri, 17 Sep 2004 03:24:51 GMT


I fail to understand the part:


What do you mean by "if @projectid" in this context. That part seem to be missing something like:
"if @projectid IS NULL"...

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/









SQL Server >> Sproc question *should be easy, hopefully*

by Weston Weems » Fri, 17 Sep 2004 03:40:56 GMT

Well heres some PSEUDO code without knowing how tsql
SHOULD do it.

SELECT *
FROM
Issues
WHERE
If(@ProjectId != -1){
Project = @ProjectId
}
and
....

Eg, if projectId = -1, I basically want to remove project
from the parameter list

So Id have

SELECT *
FROM
Issues
WHERE
<OtherConditions>

Thanks



Sproc question *should be easy, hopefully*

by Tibor Karaszi » Fri, 17 Sep 2004 04:43:14 GMT

I see. Something like:

WHERE
Project = CASE WHEN @ProjectId = -1 THEN Project ELSE @ProjectId
AND---

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/








Similar Threads

1. (Hopefully) Easy SQL 6.5 Question - Getting Table Structure

Hi All

I need to tell a colleague how to get the structure (table name +
column names + primary key + index etc) of each table in a SQL 6.5
database.

I can't access the server as it is on another site several 100's of
miles away, so I need step by step destructions on how to do it. I'm
not that hot at SQL and my colleague is even worse so really clear
instructions would be appreciated.

Many Thanks

Taddub

2. (Hopefully) easy question for table/matrix guru - SQL Server

3. 2 Easy Reporting Services Questions (hopefully)

Good morning,

1. It is my understading that you cannot merge cells in a column in a table 
(report item) but you can in a row. Does anybody know of a workaround to this 
and can possibly explain to me why you cant merge cells in a cloumn?

2. I have a value, say 2, and i want 2 stars or '**' to appear on my report 
rather than the text '2'. Does anybody know if this is easy to do or have a 
small bit of sql code that will achieve my desired result?
-- 
Thanks in advance,
Dave Hunt

4. Try again - please help 2 hopefully easy questions for the experienced - SQL Server

5. Help with custom total in matrix (hopefully easy adjustment)

Hey guys.  I have a matrix that is working the way I want it as far as 
groupings and data.  I am doing a custom total that works for the first row 
group with the following code:

Private currentTotal As Double = 0
Function SetCurrentValue(ByVal currentValue As Double) As Double
	currentTotal += currentValue 
	return currentTotal
End Function

Function GetCurrentValue() As Double
	return currentTotal 
End Function 

Function ResetTotal() As Boolean
	currentTotal=0
	return True
End Function 

In my detail I have:

=IIf(Fields!WC_GROUP.Value = "007", Code.MyFunc(Fields!WC_GROUP.Value, 
Fields!WC_TOTALS_DIVIDEND_ROUNDED.Value), 
IIf(Fields!WC_GROUP.Value = "008", Code.MyFunc(Fields!WC_GROUP.Value, 
Fields!WC_TOTALS_DIVIDEND_ROUNDED.Value), Nothing))

If I use only the first IIF statement I get the correct values 19, 38 , 57, 
76, 95, 114, 133, 152, 171, 190, 209, and 228.

If I use both IIf statements I get 19, 57, 95, 133, 171, 209, 247, 285, 323, 
361, 399, 437 in the first row and in the second row I get:

494, 532, 570, 608, 646, 684, 722, 760, 798, 836, 874, 912

I need to run the reset method in between row groupings to get it to go back 
to 19 for the second row (it will be a different starting value eventually, 
but for now I need it to reset).  

I tried putting the code as a second row grouping and the column subtotal, 
but it won't reset in the proper spot.  Let me know!

Thanks!,

BJ

6. SQL Server Management Studio Easy Easy Question

7. last question on SQL string (hopefully)

thanks for your patience all

nearly done on the DB SQL string..


now I need to do once last check...check on an empty field

something like :- select from users where field not empty

which in any normal world might look like

SELECT * FROM users WHERE this_field <> ""

but problems here with inverted commas etc..

I've tried a whole bunch of strings but none seem to work, cos I'm just so
damn thick!!!!

and the solution is...step forward people cleverer (great word) than me....

thanks again


VERY VERY frustrating knowing exactly what you want to do but lacking the
skills to do it




8. Hopefully a basic query question