Thursday, March 29, 2012
Equivalant Exception for DUP_VAL_ON_INDEX for SQL Server
We are in the process of migrating the Oracle database to SQL Server. We need the help on the Exception Handling in SQL Server.
The existing Oracle stored procedure is using the Exception DUP_VAL_ON_INDEX, which raises when the duplicate values gets inserted in the Indexed column. (typcially used with INSERT statement)
We need the equivalant statement for the exception mentioned above.
I request you to elp us out in this case.
Thanking in advance.
Duplicates for a unique index insert return the error number
is 2601. The error message depends on the object name but
it's:
Cannot insert duplicate key row in object '%.*ls' with
unique index '%.*ls'.
-Sue
On Wed, 31 Mar 2004 03:21:06 -0800, Aparna
<aparna.shirodkar@.lycos.com> wrote:
>Hello,
>We are in the process of migrating the Oracle database to SQL Server. We need the help on the Exception Handling in SQL Server.
>The existing Oracle stored procedure is using the Exception DUP_VAL_ON_INDEX, which raises when the duplicate values gets inserted in the Indexed column. (typcially used with INSERT statement)
>We need the equivalant statement for the exception mentioned above.
>I request you to elp us out in this case.
>Thanking in advance.
|||Hello Sue,
Good Morning. Thank you very much for the very useful help. Yesterday late evening i tried the same and was at the conclusion of the error no. 2601 as the equivalant in SQL.
Your ans. supports that and i an confirmed now.
Thank you once again.
Equivalant Exception for DUP_VAL_ON_INDEX for SQL Server
We are in the process of migrating the Oracle database to SQL Server. We nee
d the help on the Exception Handling in SQL Server.
The existing Oracle stored procedure is using the Exception DUP_VAL_ON_INDEX
, which raises when the duplicate values gets inserted in the Indexed column
. (typcially used with INSERT statement)
We need the equivalant statement for the exception mentioned above.
I request you to elp us out in this case.
Thanking in advance.Duplicates for a unique index insert return the error number
is 2601. The error message depends on the object name but
it's:
Cannot insert duplicate key row in object '%.*ls' with
unique index '%.*ls'.
-Sue
On Wed, 31 Mar 2004 03:21:06 -0800, Aparna
<aparna.shirodkar@.lycos.com> wrote:
>Hello,
>We are in the process of migrating the Oracle database to SQL Server. We ne
ed the help on the Exception Handling in SQL Server.
>The existing Oracle stored procedure is using the Exception DUP_VAL_ON_INDE
X, which raises when the duplicate values gets inserted in the Indexed colum
n. (typcially used with INSERT statement)
>We need the equivalant statement for the exception mentioned above.
>I request you to elp us out in this case.
>Thanking in advance.|||Hello Sue,
Good Morning. Thank you very much for the very useful help. Yesterday late e
vening i tried the same and was at the conclusion of the error no. 2601 as t
he equivalant in SQL.
Your ans. supports that and i an confirmed now.
Thank you once again.
equallent to decode in oracle?
update propertytable set visible =decode(propertyid, 1,0, 2,0, 3,1, 5,1, 6,1, 7,0, 9,1, 10,1, 11,0, 14,1, 30,1, 38,1, 60,0, 232,0, 233,0, 415,1, 605,0) where parentid between 2000006001 and 2000006020
Thanks...I'd use the SQL-92 syntax, the [url=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ca-co_5t9v.asp]CASE]/url] operator.
-PatP|||Thanks Pat,
I have tried it But, have a question on how to handle the UPDATE. Is there anything wrong in the below statement?
UPDATE Propertytable set visible =
CASE
WHEN propertyid =1 THEN 0
WHEN propertyid=2 THEN 0
WHEN propertyid =3 THEN 1
WHEN propertyid =5 THEN 1
WHEN propertyid =6 THEN 1
WHEN propertyid =7 THEN 0
WHEN propertyid =9 THEN 1
WHEN propertyid =10 THEN 1
WHEN propertyid =11 THEN 0
WHEN propertyid =4 THEN 1
WHEN propertyid =30 THEN 1
WHEN propertyid =38 THEN 1
WHEN propertyid =60 THEN 0
WHEN propertyid =232 THEN 0
WHEN propertyid =233 THEN 0
WHEN propertyid =415 THEN 1
WHEN propertyid =605 THEN 0
END,
where parentid between 2000006001 and 2000006020|||One stinking little comma!UPDATE Propertytable
SET visible =
CASE
WHEN propertyid =1 THEN 0
WHEN propertyid=2 THEN 0
WHEN propertyid =3 THEN 1
WHEN propertyid =5 THEN 1
WHEN propertyid =6 THEN 1
WHEN propertyid =7 THEN 0
WHEN propertyid =9 THEN 1
WHEN propertyid =10 THEN 1
WHEN propertyid =11 THEN 0
WHEN propertyid =4 THEN 1
WHEN propertyid =30 THEN 1
WHEN propertyid =38 THEN 1
WHEN propertyid =60 THEN 0
WHEN propertyid =232 THEN 0
WHEN propertyid =233 THEN 0
WHEN propertyid =415 THEN 1
WHEN propertyid =605 THEN 0
END
WHERE parentid between 2000006001 and 2000006020-PatP|||Thanks a lot Pat, you are awesome...|||Pat?
What the hell is that?
UPDATE Propertytable
SET visible =
CASE
WHEN propertyid IN (1,2,11,60,232,233,605) THEN 0
WHEN propertyid IN (3,5,6,9,10,4,30,38,415) THEN 1
END
WHERE parentid between 2000006001 and 2000006020|||I am migrating the oracle related scripts to SQL Server.:-)|||What the hell is that?For somebody comming from an Oracle background, the right way to do it. Actually, listing the elements is preferred syntactically for a lot of reasons, although your solution is a lot easier to type.
-PatP|||I am migrating the oracle related scripts to SQL Server.:-)
I was refering to Pat not using IN...
You do know that if it's not one of those values, you'll get a Null value
EDIT: Did the version after 8i get CASE?
DECODE is sooooooooooo painful...
Tried to write CASE as a udf in Oracle 8i once...gave up...|||Yes, if you don't include an ELSE clause to cover missing values then you'll get a NULL for values that aren't listed. In most cases, that is exactly what I'd like, although kingno1 might or might not like that behavior.
Once you get used to Decode(), it really isn't bad. Oracle users are so accustomed to it that they consider it natural.
Yes, Oracle 9 got a lot of nifty additions that bring it much closer to the SQL-92 standard. There are still a number of behaviors for otherwise standard SQL constructs that Oracle has long supported/encouraged in PL/SQL that will pretty likely keep PL/SQL from ever reaching standards compliance, but it is doing a lot better than it did in the past.
I would have loved to have had the rights to sell bleacher space for folks to watch you trying to code CASE using Oracle 8i. I could have made a fortune!
-PatP|||How do you do >, <, <>, <=, >=?
I actually figured out how to do it...
Anyone?sql
Equalize mis-synched tables
tables. The subscriber has a few more rowguids than Publisher even after
synching. Synch glip or conflict or such.
What is the best practice to get them matching without cascading more
oddities to other subscribers?
When I try a meaningless update, to kick in the repl trigger, it doesn't
seem to move over. Delete and reinsert? Same Guid or new?
thanks for any suggestions.
Mike
If data falls in the woods and nobody is there to see it ...... ?
This can happen in several circumstances that I know of. Most likely it's
from when you bulk insert the rows and choose the defaults, then
FIRE_TRIGGERS is false and consequently the rows are not added to
MSmerge_contents. Also, if you do a fast-load using the Transform Data task
in DTS: In all cases case, you need to run sp_addtabletocontents to include
the rows then resynchronise. Alternatively you can use sp_mergedummyupdate
for a single row. For the fast load case, in future if you deselect the
check box the triggers will fire.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
|||Thanks Paul.
The extra rows are on my pull subscriber (server) so I used the
sp_mergedummyupdate to test. It did add a row to the msmerge_contents table
but the generation didn't transfer to the publishers _contents table.
No synch error messages/conflicts. Other data is moving fine.
The extra rows were deleted 1/2/06, reasons unknown (system delete). I
reinserted them with a std insert from a restored db. ** I kept the original
rowguid.
Mistake? I wanted to avoid getting duplicate values in the table.
The pub does have the initial delete in tombstone (orig rowguid). Would
that would filter out the rowguid for future synching?
Mike
If data falls in the woods and nobody is there to see it ...... ?
"Paul Ibison" wrote:
> This can happen in several circumstances that I know of. Most likely it's
> from when you bulk insert the rows and choose the defaults, then
> FIRE_TRIGGERS is false and consequently the rows are not added to
> MSmerge_contents. Also, if you do a fast-load using the Transform Data task
> in DTS: In all cases case, you need to run sp_addtabletocontents to include
> the rows then resynchronise. Alternatively you can use sp_mergedummyupdate
> for a single row. For the fast load case, in future if you deselect the
> check box the triggers will fire.
> Cheers,
> Paul Ibison SQL Server MVP, www.replicationanswers.com
> (recommended sql server 2000 replication book:
> http://www.nwsu.com/0974973602p.html)
>
>
|||I'm a little unsure of your current situation but if the rows don't exist at
all on the publisher then I'd delete these newly added subscriber rows, then
reinsert them and let new rowguids be created.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
Equality comparison of xml fields
* The xml field is typed DOCUMENT.XML data type instances are incomparable. XML data type preserves the content information of the XML instances and may not be an exact copy of the user-supplied XML data. Comparison depends upons the application semantics.
I can suggest the following for your application:
1) Extract scalar values (using the value() method) from the XML parameter and compare with scalar values in the stored XML field
2) Convert the XML parameter to a string representation and compare with a string representation of the stored XML field
3) Add a column that stores a hashed value of the XML instances. Get the hash value of the XML parameter and make a comparison of the hashed values. For a hash match, use #1 or #2 to ensure that the match is indeed correct. There are well known hashing methods (SHA-1 for example) that can yield good hash matches.
Hope this helps.
Thank you.|||Thanks Shankar for the reply. What I would do is break down this xml chunk into smaller content and perform the above as you suggested.
equal sign
figure it out. Does anyone know how to do this?
fieldname like '%=%'
Thanks for any help you can give!!The following works fine for me. Does it not, for you?
create table #x (blat varchar(50))
insert #x
select 'abc=def'
union all
select 'abc'
union all
select 'def'
union all
select '='
select *
from #x
where blat like '%=%'
--
Adam Machanic
SQL Server MVP - http://sqlblog.com
Author, "Expert SQL Server 2005 Development"
http://www.apress.com/book/bookDisplay.html?bID=10220
"Rick" <rick@.di-wave.com> wrote in message
news:OWPoYnp2HHA.728@.TK2MSFTNGP05.phx.gbl...
>I need to search for the equal sign in field data. Have not been able to
>figure it out. Does anyone know how to do this?
> fieldname like '%=%'
> Thanks for any help you can give!!
>|||Hmmm No it does not work for me. I will make sure I have not missed typed
something.
Thanks!!
"Adam Machanic" <amachanic@.IHATESPAMgmail.com> wrote in message
news:eijhwsp2HHA.6072@.TK2MSFTNGP03.phx.gbl...
> The following works fine for me. Does it not, for you?
>
> --
> create table #x (blat varchar(50))
> insert #x
> select 'abc=def'
> union all
> select 'abc'
> union all
> select 'def'
> union all
> select '='
> select *
> from #x
> where blat like '%=%'
> --
>
> --
> Adam Machanic
> SQL Server MVP - http://sqlblog.com
> Author, "Expert SQL Server 2005 Development"
> http://www.apress.com/book/bookDisplay.html?bID=10220
>
> "Rick" <rick@.di-wave.com> wrote in message
> news:OWPoYnp2HHA.728@.TK2MSFTNGP05.phx.gbl...
>|||If you copy and paste the example I posted, and run it, what is the output?
Adam Machanic
SQL Server MVP - http://sqlblog.com
Author, "Expert SQL Server 2005 Development"
http://www.apress.com/book/bookDisplay.html?bID=10220
"Rick" <rick@.di-wave.com> wrote in message
news:e$wMiyp2HHA.5740@.TK2MSFTNGP04.phx.gbl...
> Hmmm No it does not work for me. I will make sure I have not missed typed
> something.
> Thanks!!
>
> "Adam Machanic" <amachanic@.IHATESPAMgmail.com> wrote in message
> news:eijhwsp2HHA.6072@.TK2MSFTNGP03.phx.gbl...
>
equal sign
figure it out. Does anyone know how to do this?
fieldname like '%=%'
Thanks for any help you can give!!
The following works fine for me. Does it not, for you?
create table #x (blat varchar(50))
insert #x
select 'abc=def'
union all
select 'abc'
union all
select 'def'
union all
select '='
select *
from #x
where blat like '%=%'
Adam Machanic
SQL Server MVP - http://sqlblog.com
Author, "Expert SQL Server 2005 Development"
http://www.apress.com/book/bookDisplay.html?bID=10220
"Rick" <rick@.di-wave.com> wrote in message
news:OWPoYnp2HHA.728@.TK2MSFTNGP05.phx.gbl...
>I need to search for the equal sign in field data. Have not been able to
>figure it out. Does anyone know how to do this?
> fieldname like '%=%'
> Thanks for any help you can give!!
>
|||Hmmm No it does not work for me. I will make sure I have not missed typed
something.
Thanks!!
"Adam Machanic" <amachanic@.IHATESPAMgmail.com> wrote in message
news:eijhwsp2HHA.6072@.TK2MSFTNGP03.phx.gbl...
> The following works fine for me. Does it not, for you?
>
> --
> create table #x (blat varchar(50))
> insert #x
> select 'abc=def'
> union all
> select 'abc'
> union all
> select 'def'
> union all
> select '='
> select *
> from #x
> where blat like '%=%'
> --
>
> --
> Adam Machanic
> SQL Server MVP - http://sqlblog.com
> Author, "Expert SQL Server 2005 Development"
> http://www.apress.com/book/bookDisplay.html?bID=10220
>
> "Rick" <rick@.di-wave.com> wrote in message
> news:OWPoYnp2HHA.728@.TK2MSFTNGP05.phx.gbl...
>