Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fill a new table with data acquired using a SELECT statement 2

Status
Not open for further replies.

diaglez

Technical User
Jun 20, 2006
18
ES
Hi, I need to fill a new table with data acquired using a SELECT statement

e.g.

MS SQL SERVER

1** I create the table:
--------inicio--------
Create Table TACCESOS2
(
CODIGO INT,
NOMBRE NVARCHAR(20),
FECHA NVARCHAR(20),
HORA NVARCHAR(20),
TERMINAL SMALLINT
);
---------fin----------

2** I want to insert results of this statement in the new table:

SELECT PECODI AS CODIGO, PENOMB AS NOMBRE, SUBSTRING(CAST(FIFECH AS NVARCHAR),1,11) AS FECHA, CAST(FIHORA AS NVARCHAR) AS HORA, FINODO AS TERMINAL
FROM FFICHA,FPERSO
WHERE SUBSTRING(CAST(FFICHA.FICODI AS NVARCHAR),2,11) = FPERSO.PECODI

but I don´t know how to do it

Thanks


 
Code:
INSERT INTO TACCESOS2 (CODIGO,NOMBRE, FECHA,HORA,TERMINAL)
SELECT PECODI AS CODIGO,
       PENOMB AS NOMBRE,
       SUBSTRING(CAST(FIFECH AS NVARCHAR),1,11) AS FECHA,
       CAST(FIHORA AS NVARCHAR) AS HORA, FINODO AS TERMINAL
FROM FFICHA,FPERSO
WHERE SUBSTRING(CAST(FFICHA.FICODI AS NVARCHAR),2,11) =
      FPERSO.PECODI

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Try

INSERT INTO TACCESOS2
( CODIGO, NOMBRE, FECHA, HORA, TERMINAL )
SELECT PECODI AS CODIGO, PENOMB AS NOMBRE, SUBSTRING(CAST(FIFECH AS NVARCHAR),1,11) AS FECHA, CAST(FIHORA AS NVARCHAR) AS HORA, FINODO AS TERMINAL
FROM FFICHA,FPERSO
WHERE SUBSTRING(CAST(FFICHA.FICODI AS NVARCHAR),2,11) = FPERSO.PECODI


Hope this helps
 
:eek:)
Why sorry? The main goal of this forum is to help :eek:)

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
I already done it but I got this error message:
------------
Msg 8152, Level 16, State 13, Line 1
String or binary data would be truncated.
The statement has been terminated.
------------

Thanks a lot
 
Are your datatypes identical?

Open up the table designer for the tables:

TACCESOS2
FFICHA
FPERSO

and check

the columns:

CODIGO INT,
NOMBRE NVARCHAR(20),
FECHA NVARCHAR(20),
HORA NVARCHAR(20),
TERMINAL SMALLINT

match those in the tables you are SELECTing data from.

Cheers
 
Always set length of varchar or nvarchar types. I can't remember how is the default length.
Try this:
[/code]
INSERT INTO TACCESOS2 (CODIGO,NOMBRE, FECHA,HORA,TERMINAL)
SELECT PECODI AS CODIGO,
PENOMB AS NOMBRE,
SUBSTRING(CAST(FIFECH AS NVARCHAR(200)),1,11) AS FECHA,
CAST(FIHORA AS NVARCHAR(200)) AS HORA,
FINODO AS TERMINAL
FROM FFICHA,FPERSO
WHERE SUBSTRING(CAST(FFICHA.FICODI AS NVARCHAR(200)),2,11) =
FPERSO.PECODI
[/code]


Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top