June 5, 2014 at 2:38 pm
Hello,
I have a table, where columns:
[Zvans no] type as nvarchar(255)
[Zvans uz] type as nvarchar(255)
2023317620263309
2023317622843223
2023317625432616
2023317620233176
This query is working fine:
declare @first table ( nr varchar(10), nr3 varchar(10),poz int)
insert into @first (nr,nr3)
Select '1111','1ffn131' union all
Select '2222','2asa225' union all
Select '3333','3333' union all
Select '4444','4444'
update @first
set poz=1
from @first where nr like '%'+nr3+'%'
But the query isin't working:
update numbers
set oper=1
from numbers where [Zvans no] like '%'+[Zvans uz]+'%'
Why? I don't getting any values when i am running this query for numbers... Is it very strange... 🙁
June 5, 2014 at 2:46 pm
What's wrong with the code?
It's updating one row. What's missing?
CREATE TABLE numbers(
[Zvans no] nvarchar(255),
[Zvans uz] nvarchar(255),
oper int)
INSERT INTO numbers([Zvans no],[Zvans uz]) SELECT
'20233176','20263309' UNION ALL SELECT
'20233176','22843223' UNION ALL SELECT
'20233176','25432616' UNION ALL SELECT
'20233176','20233176'
SELECT * FROM numbers
update numbers
set oper=1
from numbers where [Zvans no] like '%'+[Zvans uz]+'%'
SELECT * FROM numbers
June 5, 2014 at 2:53 pm
Yeas, this code is good, but some is bad in my table, perhaps with data, because this query doesn't working and I don't know why...
June 5, 2014 at 2:59 pm
Myke85 (6/5/2014)
Yeas, this code is good, but some is bad in my table, perhaps with data, because this query doesn't working and I don't know why...
Well unless you can tell us more than "it isn't working" we can't offer much assistance. What do you mean it isn't working?
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
June 5, 2014 at 3:03 pm
"Isin't working" is meaning that after this qeury in my db:
update numbers
set oper=1
from numbers where [Zvans no] like '%'+[Zvans uz]+'%'
I am getting - (0 row(s) affected)
June 5, 2014 at 3:09 pm
Myke85 (6/5/2014)
"Isin't working" is meaning that after this qeury in my db:
update numbers
set oper=1
from numbers where [Zvans no] like '%'+[Zvans uz]+'%'
I am getting -
(0 row(s) affected)
That means you don't have any have rows that meet the criteria. In other words, none of the rows have a value in [Zvans no] that is contained within the value of [Zvans uz]. Are the values you posted here a realistic representation of the real data?
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
June 8, 2014 at 11:53 am
Yes, I understand that i don't get any rows for this query.
Yes, It is the really data and it is very strange for this that i have written for you.
June 9, 2014 at 7:46 am
Myke85 (6/8/2014)
Yes, I understand that i don't get any rows for this query.Yes, It is the really data and it is very strange for this that i have written for you.
There is something I am not understanding. You seem to understand why you don't the results you expect from this query yet at the same time you say it is strange. What is the question here? We can help but we don't understand what the problem is.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
June 9, 2014 at 7:55 am
I don't see what the problem is either. Perhaps you could explain what you mean.
However, I did notice that you're comparing a varchar column against an nvarchar value. Ideally, the data types should be the same to avoid the implicit cast.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply