all groups > sql server programming > february 2006 >
You're in the

sql server programming

group:

Table Variable Problem, Please help!!!!!!


Table Variable Problem, Please help!!!!!! Scarlet
2/1/2006 11:00:49 PM
sql server programming:
This totally weird, I have no clue why it's happening. As a part of a script
which loops through some records and does stuff based on that, I have an
update state ment like following:

Declare @TMPVAR TABLE (myCol nvarchar(3))
/*Loop starts here, @TMPVAR is populated with a 3 character string*/

/*some code here*/
Update myTable set Stat=1 When otherCol IN (Select myCol from @TMPVAR)
/*some code here*/

/* Loop ends here */

The above works fine, but just gets stuck on some values. @TMPVAR might have
two or most often 1 rows.

Now if I use that value hard coded like this:

Update myTable set Stat=1 When otherCol IN ('XXX')

it works fine. Strange enoguh if I use a normal variable such as

Declare @myVar as nvarchar(3)

And dump that value into this variable from the table variable, it works
fine. Just that table variable, and just on that special value causes the
script to get stuck. I know it totally doesnt make any sense, as it doesnt to
me, but, I am frustrated. I tries to put the whole string into a sp to debug
it, but enterprise manager hangs on me!

So the questions are:
1-Has anybody have such an experience?
2-Where should I look at? (I am not using any reserved word, I am sure)
3-Is there anyway to see what actually is happening at that point of time
when it's stuck?
4-If it is a deadlock, how long should sql server wait for it? I have waited
about an hour and nothing happened, this part of the script doesnt take more
than 50 s to run normally. Why a deadlock anyway?

Thanks

Re: Table Variable Problem, Please help!!!!!! Uri Dimant
2/2/2006 12:00:00 AM
Scarlet

It is hard to suggest something without seeing the actual source + sample
data.

Can you post some data to reproduce the problem?



[quoted text, click to view]

Re: Table Variable Problem, Please help!!!!!! Uri Dimant
2/2/2006 12:00:00 AM
Hi
I did want you to put a real data here. Just to reproduce the problem that's
all

create table #t
(
col1 int not null primary key,

.....
)

insert into #t values (1,'bla bla')



[quoted text, click to view]

Re: Table Variable Problem, Please help!!!!!! Uri Dimant
2/2/2006 12:00:00 AM
Uh, sorry
It should be
I did NOT want you to put a real data here.



[quoted text, click to view]

Re: Table Variable Problem, Please help!!!!!! Uri Dimant
2/2/2006 12:00:00 AM
Scalet
Try


Update myTable set Stat=1 When otherCol IN (N'XXX')
declare @myvar NVARCHAR(3)
SET myvar =N'blblabnala'
Update myTable set Stat=1 When otherCol=myvar
or
Update myTable set Stat=1 When otherCol IN (Select myCol from @TMPVAR as t
WHERE t.PK=myTable.PK)

By PK I mean a Primary Key



[quoted text, click to view]

Re: Table Variable Problem, Please help!!!!!! Scarlet
2/2/2006 1:09:28 AM
Hi Uri

No sorry, I can't. The data and the actual script are strictly confidential
and as I said this behaviour is very strange and the situation is exactly as
I described. I haven't tried on a subset of data to see what happens, and
also I am going to use EXISTS instead of IN, and get back to you with the
results.

Thanks

[quoted text, click to view]
Re: Table Variable Problem, Please help!!!!!! Scarlet
2/2/2006 1:41:26 AM
Uri,

I understand you, but the point is the situations is so bizzar, that I am
not sure if it is reproducible by sample data. The actual codes loops through
a table with 35 rows and for each row performs several tasks, a lot of things
happen, but only for one of the rows, and only in one update statement (there
are few with almost the same syntax) gets stuck, without error, nothing, just
stuck there.
And if I hard code or use a normal variable it will be fine.

[quoted text, click to view]
AddThis Social Bookmark Button