views:

53

answers:

1

I got a table variable @RQ, I want it updated using a table-valued function. Now, I think I do the update wrong, because my function works...

The function:

ALTER FUNCTION [dbo].[usf_GetRecursiveFoobar]
(   
    @para int,
    @para datetime,
    @para varchar(30)
)


RETURNS @ReQ TABLE
(
    Onekey int,
    Studnr nvarchar(10),
    Stud int,
    Description nvarchar(32),
    ECTSGot decimal(5,2),
    SBUGot decimal(5,0),
    ECTSmax decimal(5,2),
    SBUmax decimal(5,0),
    IsFree bit,
    IsGot int,
    DateGot nvarchar(10),
    lvl int,
    path varchar(max)
)

AS
BEGIN;

WITH RQ
AS
(
    --RECURSIVE QUERY
)

INSERT @ReQ

SELECT
    RQ.Onekey,
    RQ.Studnr,
    RQ.Stud,
    RQ.Description,
    RQ.ECTSGot,
    RQ.SBUGot,
    RQ.ECTSmax,
    RQ.SBUmax,
    RQ.IsFree,
    RQ.IsGot,
    RQ.DatumGot,
    RQ.lvl,
    RQ.path

    FROM
        RQ

    RETURN

END

Now, when I run a simple query:

DECLARE @ReQ TABLE
(
     OnderwijsEenheid_key int,
     StudentnummerHSA nvarchar(10),
     Student_key int,
     Omschrijving nvarchar(32),
     ECTSbehaald decimal(5,2),
     SBUbehaald decimal(5,0),
     ECTSmax decimal(5,2),
     SBUmax decimal(5,0),
     IsVrijstelling bit,
     IsBehaald int,
     DatumBehaald nvarchar(10),
     lvl int,
     path varchar(max)
)

INSERT INTO @ReQ

SELECT *
FROM usf_GetRecursiveFoobar(@para1, @para2, @para3)

I got error:

Msg 8152, Level 16, State 13, Line 20 String or binary data would be truncated. The statement has been terminated.

Why? What to do about it?

A: 

Ok. my fault...

a varchar(10) was tried to be filled with a 10-character long string. So it failed...

Joris