# SQL Example Using Clarion

**URL:** <https://clarionhub.com/t/sql-example-using-clarion/165>\
**Category:** questions\
**Created:** [August 21, 2014, 1:44pm UTC](https://clarionhub.com/t/sql-example-using-clarion/165 "2014-08-21T13:44:28Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![brahn](https://clarionhub.com/user_avatar/clarionhub.com/brahn/32/756_2.png) [@brahn](https://clarionhub.com/u/brahn)\
**Post date:** [December 17, 2014, 2:30pm UTC](https://clarionhub.com/t/sql-example-using-clarion/165/21 "2014-12-17T14:30:24Z")

</div>

😄

Post some code and I will see if I can spot anything!

---

<div class="post-metadata">

**Author:** ![RamonBoorges](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/c6cbf5/32.png) [@RamonBoorges](https://clarionhub.com/u/RamonBoorges)\
**Post date:** [December 17, 2014, 3:01pm UTC](https://clarionhub.com/t/sql-example-using-clarion/165/22 "2014-12-17T15:01:33Z")

</div>

```
viewTabela view(RESPOSTA)
                        project(RES:COLUNA1)
                        project(RES:COLUNA2)
                        project(RES:COLUNA3)
                        project(RES:COLUNA4)
                        project(RES:COLUNA5)
                        project(RES:COLUNA6)
                        project(RES:COLUNA7)
                        project(RES:COLUNA8)
                        project(RES:COLUNA9)
end

open(viewTabela)
L:SQL = 'select * from cl_clire where cd_repre = ' & REP:Cd_Repre & ';'
RESPOSTA{PROP:SQL} = L:SQL !Dummy table
if error()
    message(errorcode() & ' ' & error() & ' ' & fileerrorcode() & ' ' & fileerror())
else
    loop
        next(viewTabela)
        if errorcode()        
            do InsertRoutine
        else
            do UpdateRoutine
        end
        break
    end
end
close(viewTabela)

```

---

<div class="post-metadata">

**Author:** ![RamonBoorges](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/c6cbf5/32.png) [@RamonBoorges](https://clarionhub.com/u/RamonBoorges)\
**Post date:** [December 17, 2014, 3:02pm UTC](https://clarionhub.com/t/sql-example-using-clarion/165/23 "2014-12-17T15:02:18Z")

</div>

The first part it’s the declaration of the View. The second part it’s the code that it’s not working.

---

<div class="post-metadata">

**Author:** ![brahn](https://clarionhub.com/user_avatar/clarionhub.com/brahn/32/756_2.png) [@brahn](https://clarionhub.com/u/brahn)\
**Post date:** [December 18, 2014, 11:36am UTC](https://clarionhub.com/t/sql-example-using-clarion/165/24 "2014-12-18T11:36:58Z")

</div>

> [@RamonBoorges](#):
>
> open(viewTabela)

You should do a check for errors after opening the view.

```auto
open(viewTabela)
if error()
  ! do something about it
end

```

and here, I think you need to explicitly list the columns you want rather than use \*. Also, I am pretty sure the `;` is unnecessary and may even cause a problem.

```auto
L:SQL = 'select * from cl_clire where cd_repre = ' & REP:Cd_Repre & ';'

```

What data type is this one?

```auto
REP:Cd_Repre

```

---

<div class="post-metadata">

**Author:** ![RamonBoorges](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/c6cbf5/32.png) [@RamonBoorges](https://clarionhub.com/u/RamonBoorges)\
**Post date:** [January 7, 2015, 12:59pm UTC](https://clarionhub.com/t/sql-example-using-clarion/165/25 "2015-01-07T12:59:43Z")

</div>

Sorry for not answering you guys. I was on vacation and started to work back today. My mistake was that I wasn’t using the view to execute the SQL statement, now everything is working. Thanks for all your help, @brahn and @rockyp.

---

<div class="post-metadata">

**Author:** ![SolucionesSS](https://clarionhub.com/letter_avatar_proxy/v4/letter/s/e495f1/32.png) [@SolucionesSS](https://clarionhub.com/u/SolucionesSS)\
**Post date:** [August 23, 2016, 3:58pm UTC](https://clarionhub.com/t/sql-example-using-clarion/165/26 "2016-08-23T15:58:59Z")

</div>

Hi hugs from Costa Rica.

Please help me, I’m trying to run a PROP : SQL in my application with the following command C6.3 , but there is no way to run . What am I doing wrong?

```auto
mytable{prop: sql} = 'truncate table dbo.mae06f_buscador'

If Errorcode() = 90
           Message ( Errorfile ())
           Message ( Fileerrorcode ())
end

```

“mytable” its a table SQL and defined in the Clarion Dictionary.

Always returns error S0002 in the table mae06f\_buscador

Thank you !!!

---

<div class="post-metadata">

**Author:** ![brahn](https://clarionhub.com/user_avatar/clarionhub.com/brahn/32/756_2.png) [@brahn](https://clarionhub.com/u/brahn)\
**Post date:** [August 24, 2016, 6:45am UTC](https://clarionhub.com/t/sql-example-using-clarion/165/27 "2016-08-24T06:45:41Z")

</div>

I have never used `ErrorFile()`, had to look that one up!

Whilst it might be handy probably what you actually want there is `Message(FileError())` instead.  
See if that tells you anything helpful.

---

<div class="post-metadata">

**Author:** ![Michael\_Boorman](https://clarionhub.com/user_avatar/clarionhub.com/michael_boorman/32/1525_2.png) [@Michael\_Boorman](https://clarionhub.com/u/Michael_Boorman)\
**Post date:** [February 17, 2020, 9:34am UTC](https://clarionhub.com/t/sql-example-using-clarion/165/28 "2020-02-17T09:34:26Z")

</div>

Thank you,  
This just helped me find my fault after 3 days of searching in around 5 minutes.

[Previous page](https://clarionhub.com/t/sql-example-using-clarion/165.md?page=1)
