SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Query Help


Query Help

Author
Message
rocky_498
rocky_498
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1088 Visits: 1417
Hi guys,

Need help in sql query, Let me let you what i need, during the S.P i want to like
to use this LOGIC, if EID = 0 and PID = 0 then don't run UDF.

Here is the syntax

LEFT OUTER JOIN Information_Sales A ON Case IF EID = 0 or PID = 0 then SID = 148 ELSE UDF.NEW (EID,PID) = A.SID

Please let me know if my question is not clear.

Thanks in advance..
CapnHector
CapnHector
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3087 Visits: 1789
can you post DDL and Sample data? While things may seem simple the udf and the the query you are trying and/or the outcome you are trying to get will help us immensely


For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden for the best way to ask your question.

For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw

Need to Split some strings? Jeff Moden's DelimitedSplit8K
Jeff Moden's Cross tab and Pivots Part 1
Jeff Moden's Cross tab and Pivots Part 2
The Dixie Flatline
The Dixie Flatline
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12380 Visits: 6903

LEFT OUTER JOIN Information_Sales A ON Case IF EID = 0 or PID = 0 then SID = 148 ELSE UDF.NEW (EID,PID) = A.SID



Its important to remember that a CASE expression is an expression, which produces a single scalar value. It is not an IF clause.

Assuming that the SID = 148 and A.Sid are the same column. You want something more like this

LEFT OUTER JOIN Information_Sales A on A.SID = Case When EID = 0 then 148 when PID = 0 then 148 else UDF.NEW (EID,PID) end

---------
Note: NO guarantees on performance of such a join. You may well be better off doing separate queries


LEFT OUTER JOIN Information_Sales A on SID = 148
WHERE EID = 0 or PID = 0




LEFT OUTER JOIN Information_Sales A on UDF.NEW (EID,PID)
WHERE EID <> 0 and PID <> 0



As has already been pointed out. A lot more information is needed before anyone can give you solid, specific advice.

__________________________________________________

Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
rocky_498
rocky_498
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1088 Visits: 1417
Thanks for help guys,

Its a 18 Pages S.P, its hard for me to through all logic here, that's what i want

LEFT OUTER JOIN Information_Sales A on A.SID = Case When EID = 0 then 148 when PID = 0 then 148 else UDF.NEW (EID,PID) end

I checked Performance wise its ok not bad.

Thanks all.....
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search