SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


For varchar(max) should i use normarl update or .write in following situation


For varchar(max) should i use normarl update or .write in following situation

Author
Message
rajemessage 14195
rajemessage 14195
Say Hey Kid
Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)

Group: General Forum Members
Points: 666 Visits: 366
Hi,

I want to update a col , which is null initially.

and i have to run UPDATE STMT at many places becuase it keeps error history for the row sprated by | and :

It can be done it two way.
1)
CREATE TABLE #remarkT
(ID int NOT NULL PRIMARY KEY,
Remark varchar(max));
GO

INSERT INTO #remarkT
VALUES (1, '');
-- Output for controll
SELECT * FROM #remarkT;


UPDATE #remarkT
SET Remark .Write(' error2: message2 , procedure2 etc|', LEN(Remark), NULL)
WHERE ID = 1;
SELECT * FROM #remarkT;

DROP TABLE #remarkT;


2)
UPDATE #remarkT SET Remark = ISNULL(Remark,'') + 'error1: message , procedure etc|'
WHERE ID =1

SELECT * FROM #remarkT


-----------------------------------------------------------------------

Q1) Please tel me which one is good in my situation.

Q2) Please tel me is there any better way to accomplish it.

Q3) It gives error if i put null in first insert stmt, so i have to put '' in insert stmt,
but that does not matter i am ready to put empty '' initially.

Is there any other way so that i can keep NULL initially in my col for each row IN #remarkT , except the normal update stmt.


yours sinclerely
twin.devil
twin.devil
SSCertifiable
SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)

Group: General Forum Members
Points: 5554 Visits: 2692
you can use the 2nd option, Varchar(MAX) can be used like regular varchar(50). no need to use Mutator "Wite()". keep it simple.

i would suggest that to avoid the null value in the column you can use the default at the table definition. like this


CREATE TABLE #remarkT
(ID int NOT NULL PRIMARY KEY,
Remark varchar(max) Default(''));
GO



hope it helps
rajemessage 14195
rajemessage 14195
Say Hey Kid
Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)

Group: General Forum Members
Points: 666 Visits: 366
thank u,

I wanted to know , why msdn says to use it , though the excution plan shows some more task is done
when some .write is used.

yours sincerley
twin.devil
twin.devil
SSCertifiable
SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)

Group: General Forum Members
Points: 5554 Visits: 2692
please share that execution plan.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search