Checking existing data

  • Thread starter Thread starter Bonjour
  • Start date Start date
B

Bonjour

Hi everybody !

I' d like to check data before inserting.

Select @nb = Count (idCustomer)
From Customer
Where company like '%' + @company+ '%'

If "PEUGEOT SA" already exists, @nb > 0 if I enter "PEUGEOT".
On the other hand, if "PEUGEOT" exists, @nb =0 if I enter "PEUGEOT SA".

I tried to complete ma stored procedure:

or @companylike '%' + company+ '%'

but it doesn't work.
Thanks in advance for any suggestion.
 
Hi,

If the one data instance can be a super set of other data instance in a data
domain, then don't use the like operator.
eg) data1 = "PEUGEOT SA"
data2 = "PEUGEOT"
Here data1 is the superset of data2.
So don't use the like operator. Use the = operator.


Regards,
R.Balaji
 
If you really want to use the like operator with % in front and end, do it
like this:

set @company = '%' + @company + '%'

select @nb = count(idCustomer) from customer where company like @company


Arild
 
Thanks for answering even if that doesn't solve my problem ;-)
I'd like to make a large search so I need the like operator.
 
It's what I made but this request does't return any result if the company
name's length stored in the database is shorter than the name entered:

Select @nb = Count (idCustomer)
From Customer
Where company like '%PEUGEOT SA%'

@nb = 0 if there's already a company PEUGEOT.

Thanks all the same.
 
Hi,

Then you need to check if the text is LIKE the column OR if the column is
LIKE the text :

Select @nb = Count (idCustomer)
From Customer
Where ( company like '%' + @company+ '%' ) OR ( @company like '%' + company
+ '%' )

The query above should match your example.

Cheers,
 
Hi Bonjour,

Bonjour said:
It's what I made but this request does't return any result if the company
name's length stored in the database is shorter than the name entered:

Select @nb = Count (idCustomer)
From Customer
Where company like '%PEUGEOT SA%'

@nb = 0 if there's already a company PEUGEOT.

Thanks all the same.

It would help if you could be more specific about the criteria you are
looking for. That being said, this might work for you:

Select @nb = Count (idCustomer)
From Customer
Where company like '%PEUGEOT SA%'
Or 'PEUGEOT SA' like '%' + company + '%'

Regards,
Daniel
 
Thanks everybody for your answers but your solution is what I made :

Select @nb = Count (idCustomer)
From Customer
Where company like '%' + @company + '%'
or @company like '%' + company + '%'

And it doesn't work : after a long time, the server crashes...
 
Hi,

What is the hardware and datasize of the server?

Does the server crash really ? if so what error you get?

Like is a very expensive operation .

Cheers,
 
I have a Duron 1,3 GHz with 256 Mo RAM.
The Customer table only has 500 records.

The message is "Application not avalaible" (the message for a asp.net
application in red letters) in my browser.

I have just noticed that the query works in the query analyser ! (the db
server is also my personal computer)
 
Hi,

You have another trouble then, it's not the DB stuff

paste here the complete page of error

cheers,
 
Thanks all for your help.

My trouble was due to the fact I forgot a relation between 2 tables. :-/
 
Back
Top