简体   繁体   中英

Codeigniter - Convert SQL SERVER 2008 query to codeigniter code

Can someone please help me to convert this SQL SERVER 2008 query to a codeigniter model code. Thanks a lot! =)

Here's the code:

SELECT section,
       test,
       samp_id = Stuff((SELECT ', ' + sample_name
                        FROM   tblsavesection
                               INNER JOIN tblmastersample
                                       ON tblsavesection.samp_id = tblmastersample.samp_id
                        WHERE  emp_id = '1'
                               AND tblsavesection.test_id = tbljoinedtests.test_id
                        FOR XML PATH('')), 1, 1, ''),
       Sum(quantity)AS Quantity
FROM   tblsavesection
       INNER JOIN TblJoinedTests
               ON TblSaveSection.test_id = TblJoinedTests.test_id
       INNER JOIN Tblmastersection
               ON TblSaveSection.section_id = Tblmastersection.section_id
GROUP  BY test,
          section,
          tbljoinedtests.test_id 

you can use

$query = $this->db->query("SELECT section,
           test,
           samp_id = Stuff((SELECT ', ' + sample_name
                            FROM   tblsavesection
                                   INNER JOIN tblmastersample
                                           ON tblsavesection.samp_id = tblmastersample.samp_id
                            WHERE  emp_id = '1'
                                   AND tblsavesection.test_id = tbljoinedtests.test_id
                            FOR XML PATH('')), 1, 1, ''),
           Sum(quantity)AS Quantity
    FROM   tblsavesection
           INNER JOIN TblJoinedTests
                   ON TblSaveSection.test_id = TblJoinedTests.test_id
           INNER JOIN Tblmastersection
                   ON TblSaveSection.section_id = Tblmastersection.section_id
    GROUP  BY test,
              section,
              tbljoinedtests.test_id")

get the result :

$query = $query->result(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM