nvarchar(max) variable for reciceving data with ntext type

  • In a T_SQL Block i wantto define a nvarchar(max) variable for reciceving data with ntext type.

    let me clear it more:

    i want to transfer data from Source table to Destination table , in Source table i have a field wih (ntext) type , i want to save these data in a variable with nvarchar (max) for doing some change and then transfer them to Destination table in a field with Nvarchar (max) type.

  • I'm not sure what you're doing here, but this isn't the appropriate forum. I am moving to the T-SQL forum, but if you are using SSIS, then please state that so people understand what you are doing.

  • I'm not sure to clearly understand your question but if I do there should not be any problem : this kind of conversion (from NText to NVarchar) is implicit. Try this:

    1° Create a new database and name it Misc.

    2° run this script:

    USE [Misc]

    GO

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE TABLE [dbo].[Table_1](

    [SysCounter] [int] IDENTITY(1,1) NOT NULL,

    [Value] [ntext] NULL

    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

    GO

    INSERT INTO [Table_1] ([Value])

    VALUES ('AZERTYUIOP')

    GO

    INSERT INTO [Table_1] ([Value])

    VALUES ('QSDFGHJKLM')

    GO

    INSERT INTO [Table_1] ([Value])

    VALUES ('WXCVBN')

    GO

    CREATE TABLE [dbo].[Table_2](

    [SysCounter] [int] IDENTITY(1,1) NOT NULL,

    [Value] [nvarchar](MAX) NULL

    ) ON [PRIMARY]

    GO

    CREATE PROCEDURE [dbo].[Test1_NText_To_NVarchar]

    AS

    BEGIN

    INSERT INTO [Table_2] ([Value])

    SELECT [Table_1].[Value]

    FROM [Table_1]

    END

    GO

    CREATE PROCEDURE [dbo].[Test2_NText_To_NVarchar]

    AS

    BEGIN

    DECLARE @VALUE NVARCHAR(MAX)

    SET @VALUE = (SELECT [Table_1].[Value]

    FROM [Table_1]

    WHERE [Table_1].SysCounter = 1)

    INSERT INTO [Table_2] ([Value]) SELECT @VALUE

    END

    GO

    3° Execute the 2 stored procédures Test1_NText_To_NVarchar (transfer from 1 table directly into another) and Test2_NText_To_NVarchar (transfer from one table into another using a variable).

    In both cases an implicit casting from NText to NVarchar occurs.

    I hope this will help you.

  • This should work just as you have described. Are you having any trouble with it?

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply