Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 check a string as integer

Author  Topic 

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2010-05-20 : 13:38:53
i have problem with my customer table .. . some times the same customer has multiple customer numbers

so the customer_nbr field is actually a varchar(max) field
so when a customer having multiple customer nbrs trie to insert a record in the following way
say customer john can have

0123,0234 john 1(opts in) ,04/22/2010

say he comes again the next time and opts in just the customer nbr- 0234

new record

0234 ,john ,1(opts in),04/27/2010

first time -0123, 0234
second time -0123 they are not same programmatically

how to check for this since the record should not be inserted saying you already opted in for this customer number but its not doing so...

how can i do a check for these kind of situations.. thank you

lazerath
Constraint Violating Yak Guru

343 Posts

Posted - 2010-05-20 : 14:21:00
This design does not conform to normalization rules. If you are building a transactional system, you should strive to reach the 3rd normal form.

I recommend you read up on database normalization:

http://en.wikipedia.org/wiki/Database_normalization
Go to Top of Page

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2010-05-20 : 15:49:50
quote:
Originally posted by lazerath

This design does not conform to normalization rules. If you are building a transactional system, you should strive to reach the 3rd normal form.

I recommend you read up on database normalization:

http://en.wikipedia.org/wiki/Database_normalization



Thanks for the response lazerath but the database has been designed already that way....
can i use that design to compare customer numbers...thanks in advance
Go to Top of Page

lazerath
Constraint Violating Yak Guru

343 Posts

Posted - 2010-05-20 : 18:02:11
Ok, then you will need to parse that field with a function like ParseValues:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=104485

It should be noted that there is a big performance cost to doing this every time you want to insert a record because you'll need to parse every row to find if it already exists.

A decent design would mitigate this cost.
Go to Top of Page
   

- Advertisement -