Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Only Date portion of GetDate()
Message
De
22/10/2012 13:05:47
 
 
À
22/10/2012 12:55:09
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01555465
Message ID:
01555471
Vues:
39
>Here's the SQL
>
>insert into StudentLookup 
>  Select SCN, Sname = (SLastName + ', ' + SFirstName), TCN, TName, chngdate = getdate()  from qryICECLExport
>
>
>The error I'm getting is:
>
>Msg 8152, Level 16, State 4, Line 1
>String or binary data would be truncated.
>The statement has been terminated.
>
>I thought perhaps the SName field wasn't long enough, so I expanded it (still in development phase of project), but I'm still getting the error.
>

When you have INSERT INTO you should provide the list of the fields WHERE you want to insert.
Otherwise SQL Server takes it from INFORMATION_SCHEMA.Column ordrer and try to insetr it in that order.
SQL Server DON'T match the filder by name, just by position:
DECLARE @Test1 TABLE (fld1 Date, Fld2 varchar(200))
DECLARE @Test2 TABLE (fld1 Date, Fld2 varchar(200))


INSERT INTO @Test2 VALUES (GetDate(), 'asdasda')

INSERT INTO @Test1 
SELECT Fld1, Fld2 FROM @Test2 


INSERT INTO @Test1 
SELECT Fld2, Fld1 FROM @Test2 
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform