Welcome Guest, Not a member yet? Register   Sign In
converting sql query strings to query builder
#1
Question 

I'll preface this by saying I'm trying to convert an old system from codeigniter 2.2 to 3.1. it works. and it works fine. just don't want to continue developing for 2.2. decided to move to 3.1 as an experiment.

I have the query below and several others that are similar that I'm trying to modify to use to query builder. and I really am at a loss as to how to do unions with it.  its a relatively simple query with 2 (some have more) unions and joins and stuff. And I'm at a loss as to how to do it.  somebody/anybody care to throw me a bone on this one?

any help - and i do mean any help - is greatly appreciated.

thanks in advance....

om.

--------------------------------------------------------------------
SELECT

    '1' AS pos, IFNULL(SUM(Revenue), 0.00) AS unbilled
FROM
    TimeSheet t
        INNER JOIN
    Clients c ON t.ClientNo = c.ClientNo
WHERE
    c.ClientNo IN ('10')
        AND TheDate BETWEEN CAST('2012-12-06' AS DATE) AND NOW()
        AND (t.InvoiceDate IS NULL
        OR t.InvoiceDate > NOW()
        OR t.InvoiceDate LIKE '0000-00-00')
UNION ALL SELECT
    '2' AS pos, IFNULL(SUM(Revenue), 0.00) AS unbilled
FROM
    TimeSheet t
        INNER JOIN
    Clients c ON t.ClientNo = c.ClientNo
        INNER JOIN
    Employees e ON e.ID = t.EmployeeID
WHERE
    c.ClientNo IN ('10')
        AND TheDate BETWEEN CAST('2012-12-06' AS DATE) AND NOW()
        AND (t.InvoiceDate IS NULL
        OR t.InvoiceDate > NOW()
        OR t.InvoiceDate LIKE '0000-00-00')
        AND e.Active = '2'
UNION ALL SELECT
    '3' AS pos, IFNULL(SUM(Revenue), 0.00) AS unbilled
FROM
    TimeSheet t
        INNER JOIN
    Clients c ON t.ClientNo = c.ClientNo
        INNER JOIN
    Employees e ON e.ID = t.EmployeeID
WHERE
    c.ClientNo IN ('10')
        AND TheDate BETWEEN CAST('2012-12-06' AS DATE) AND NOW()
        AND (t.InvoiceDate IS NULL
        OR t.InvoiceDate > NOW()
        OR t.InvoiceDate LIKE '0000-00-00')
        AND (e.Active = '1' OR e.Active = '0')
--------------------------------------------------------------------
OM...

-------------------------
And on the pedestal these words appear:
'My name is Ozymandias, king of kings:
Look on my works, ye Mighty, and despair!'
Nothing beside remains. Round the decay
Of that colossal wreck, boundless and bare
The lone and level sands stretch far away.
Reply


Messages In This Thread
converting sql query strings to query builder - by ozzy mandiaz - 10-05-2016, 01:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB