Embedded SQL statement

Embedded SQL statement

Post by Alex » Wed, 12 Feb 2003 02:23:21



Hello,

My problem should be very easy for any experienced SQL
programmer:

I have got the following structure.

CREATE TABLE [ouioui].[COMPATIBILITE] (
        [MIDLET_ID] [int] NOT NULL ,
        [MOBILE_ID] [smallint] NOT NULL
) ON [PRIMARY]

CREATE TABLE [ouioui].[MIDLET] (
        [MIDLET_ID] [int] IDENTITY (1, 1) NOT NULL ,
        [MIDP] [tinyint] NULL
) ON [PRIMARY]

ALTER TABLE [ouioui].[COMPATIBILITE] ADD
        CONSTRAINT [FK_COMPATIBILITE_MIDLET] FOREIGN KEY
        (
                [MIDLET_ID]
        ) REFERENCES [ouioui].[MIDLET] (
                [MIDLET_ID]
        )

I have the following data in table MIDLET:
MIDLET:
MIDLET_ID        MIDP
---------------------
1               1
2               0
3               0
4               1
5               0
6               1
...

I have no data in table COMPATIBILITE, and here is what I
want to get
(Every Midlet_ID which have 1 in the MIDP column, and a
static value '9' in column MOBILE_ID):
MIDLET_ID       MOBILE_ID
-------------------------
1               9
4               9
6               9
...

How can I do?

Thanks in advance

Alex

 
 
 

Embedded SQL statement

Post by Scott Morri » Wed, 12 Feb 2003 02:41:47


select midlet_id, cast(9 as smallint) as mobile_id
from midlet
where midp = 1
order by midlet_id

Don't see any purpose for the COMPATIBILITE table in this situation.


Quote:> Hello,

> My problem should be very easy for any experienced SQL
> programmer:

> I have got the following structure.

> CREATE TABLE [ouioui].[COMPATIBILITE] (
> [MIDLET_ID] [int] NOT NULL ,
> [MOBILE_ID] [smallint] NOT NULL
> ) ON [PRIMARY]

> CREATE TABLE [ouioui].[MIDLET] (
> [MIDLET_ID] [int] IDENTITY (1, 1) NOT NULL ,
> [MIDP] [tinyint] NULL
> ) ON [PRIMARY]

> ALTER TABLE [ouioui].[COMPATIBILITE] ADD
> CONSTRAINT [FK_COMPATIBILITE_MIDLET] FOREIGN KEY
> (
> [MIDLET_ID]
> ) REFERENCES [ouioui].[MIDLET] (
> [MIDLET_ID]
> )

> I have the following data in table MIDLET:
> MIDLET:
> MIDLET_ID        MIDP
> ---------------------
> 1 1
> 2 0
> 3 0
> 4 1
> 5 0
> 6 1
> ...

> I have no data in table COMPATIBILITE, and here is what I
> want to get
> (Every Midlet_ID which have 1 in the MIDP column, and a
> static value '9' in column MOBILE_ID):
> MIDLET_ID MOBILE_ID
> -------------------------
> 1 9
> 4 9
> 6 9
> ...

> How can I do?

> Thanks in advance

> Alex


 
 
 

1. SQL Syntax - Embedded SQL Statements

I am trying to embed one SQL statement inside another as:
           UPDATE client:
             SET country = (SELECT ID FROM countries WHERE
countries.NAME = c_country) ;
             WHERE client.client_id = sequence_table.client_id
but I receive an error message "Function name is missing)."

There is an MSDN example as follows:
           SELECT company FROM customer a WHERE ;
              EXISTS (SELECT * FROM orders b WHERE a.postalcode =
b.postalcode)
so SQL statments can be embedded in other SQL statements.

I've tried variations on the syntax without success. Can anyone help me
with this?

Thanks
Ron St.Pierre

PS In case it helps, what I am trying to do is use the COUNTRIES table
as a lookup table. The user selects the country, and the associated
Integer value from the COUNTRIES table will be inserted into my CLIENT
table.

2. MicroSQL?

3. Examples of source which contain embedded SQL statements

4. Getting SQL Server client/ODBC driver for XP Home Edition

5. Multiple Embedded SQL statements in one function

6. System GPA, VFP 5, Popup List, Functional Conversion

7. Concatenation operator in embedded SQL statements in 4GL

8. BACKUP HELP URGENT

9. Help needed on embedded sql statement

10. Need a copy of ANSI standard listing of Embedded SQL statements

11. Need help: Loading Data with C and embedded SQL statements