change data type

  • hello.,

    i want to change type of data from (ntext) to (nvarchar(max)), is there any way?and is yes, how?

    regards

  • there is a way;

    CAST(YourTextCol AS NVARCHAR(MAX))

  • if this a adhoc Query ones then cast as said above will do , if you want to change the structure of the table, yes you can

  • thank you for your reply

    i want to get data with (ntext) type from one Database and input them in a another Database with (navarchar) type and for is purpose i have a i have a Sub Query and an Insert in it, i dont know what i should do in his Subquery?

    thanks

  • nazaninahmady_sh (12/3/2008)


    thank you for your reply

    i want to get data with (ntext) type from one Database and input them in a another Database with (navarchar) type and for is purpose i have a i have a Sub Query and an Insert in it, i dont know what i should do in his Subquery?

    thanks

    All you need to do is modify the code to include the cast code that I posted earlier for the ntext col.

    Post your insert code if you need more specific help

  • Can you post the schema of the two tables and the query please?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • thank you very much for your reply

    the Schema of source table is :

    id int

    title nvarchar (250)

    body ntext

    i want to write a query for transfering data from Source table to destination table and in future this will be a step of a job.but there is a difference with these two , in my destination table i dont want to have a field with ntext type i want to to change my boby data type to nvarcharmax.

  • What does the schema of the destination table look like?

    You said you had a query to copy the data over. Can you post it?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • the Schema of Destination table is :

    id int

    title nvarchar (250)

    body navarchar(max)

    A you see the only difference between Source table and Destination table is in type of body (field), body in Source has ntext type, and in Destination has nvarchar(max) type.

    about the Query i am trying to write it but i can not,

    because the ntext is pointer and it save data in different places i can not write a query for transfering data of body ntext from source table to body nvarchar in Destination table.

    again thanks alot

  • you can use

    INSERT INTO [Destination] (id ,title ,body)

    SELECT id ,title ,cast(body as varchar(max)) from [Source]

    Though I think that the data conversion may not be needed as it should do this automaticaly, I will have to check this

  • nazaninahmady_sh (12/3/2008)


    because the ntext is pointer and it save data in different places i can not write a query for transfering data of body ntext from source table to body nvarchar in Destination table.

    You shouldn't need to do a conversion. SQL should be able to implicitly convert the ntext to nvarchar(max). Are you getting an error if you try to insert without an explicit conversion?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • sorry

    if i want to write this Query as Trigger for examinaton , what should i do?

  • What sort of trigger?

  • yes , i have problem when i want to do this conversin through SQL, because ntext is pointer az i told you it save my data in different places not in one place, and when i want to transfer all of data to another field with another data type in another table in another database i have problem because , i can not transfer all of myy data (wich is save in differet places)

    i have heard the only thing that can help is (text reader) or (pointer reader) i dont know its name exactly.

  • but for examination your previouse help i want to write an after Trigger ,please help me.

    thanks

Viewing 15 posts - 1 through 15 (of 16 total)

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