Need to convert Text field to Varchar temporarily so that I can pass to a stored procedure

风流意气都作罢 提交于 2019-12-30 06:09:21

问题


I am using a SQL 2000 database.

I am working with a database in which I cannot change the types on the tables, or the stored procedures. One of the stored procedures I need to call expects a parameter of 'text'. I can get to the text field, but I am unable to figure out who to store that in a variable or any other way to pass it into the stored procedure?

If I try and create a text variable, SQL won't let me - if I convert it to varchar I only get the first character from the text field.

Any tricks to get around this much appreciated! Thank you!


回答1:


Declare the variable of type varchar(8000)

declare @v varchar(8000)
SET @v = (SELECT CAST(textcol as varchar(8000)) FROM yourtable WHERE ....)

Obviously it might still be truncated but not at 1 character.



来源:https://stackoverflow.com/questions/4360150/need-to-convert-text-field-to-varchar-temporarily-so-that-i-can-pass-to-a-stored

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!