troubleshooting Question

function to return "T" or "F "if rows returned

Avatar of Dee
DeeFlag for United States of America asked on
Microsoft SQL Server 2005SQL
15 Comments1 Solution326 ViewsLast Modified:
I need to covert the following script to a function as follows:

    1) change hard coded branchid and nameid to input parms
    2) return "T" (char) if rows returned, "F" if no rows returned

---former borrower function
@branchid                  int,
@namesid                  int
set                              @branchid = 3208
set                              @namesid = 7619


      from contracts c
      inner join names n
      on c.branchid = n.branchid
      and c.namesid = n.namesid

      inner join vwBcontrol v
      on v.branchid = c.branchid

                  --where (loandate >= @startdate and loandate <= @enddate)
                         where (c.namesid = @namesid
                  and c.branchid = @branchid
                  and c.processstatus = 50 --former borrower
                  and c.loanamt > 0)
                  and not exists
                        (select contrnumber from contracts c2
                        where processstatus not in (3, 45, 47) --open, PandL, NonFile
                        and c2.namesid = c.namesid
                        and c2.branchid = c.branchid
                        and c2.payoutdate = c.loandate)
                        --and (c2.opendate < @enddate or (c2.opendate > c2.loandate and c2.loandate < @startdate)))
                  and not exists
                        (select contrid from transactions t
                        where transtype >= '3000' and transtype < '3999' and c.branchid = t.branchid and c.contrid = t.contrid
                        and t.namesid = c.namesid))
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 15 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros