Showing posts with label type. Show all posts
Showing posts with label type. Show all posts

Tuesday, March 20, 2012

Problem on comparing strings

Hi All,

I've problem on comparing strings with the following SQL statement:

select * from events where venue = 'myhome'

where venue is of type varchar(50)

The above SQL should return something (i.e. I've 3 events hold at my home!) but it return 0 rows.

Please kindly help.

Thanks,

stard

select * from events where venue LIKE '%myhome%'

|||

may be your column valeus have carrage return (ascii 13+10 = \r\n) character..When you see the result in GRID VIEW on Query Analyzer you wont find this character..

You can apply the following statement on select..

select * From Events Where replace(Venue,char(13)+Char(10),'')= 'MyHome'

or

select * from events where venue LIKE '%myhome%' -- It may return unexpected additional values

To remove this invalid character from your table

Update Events Set Venue = replace(Venue,char(13)+Char(10),'') Where Venue Like '%' + char(13)+Char(10) + '%'

|||

There are several possible explanitions. One is Collation differences.

What happens if you revise your query to this:

SELECT * FROM Events WHERE upper(Venue) = upper('myhome')

(This will not use indexing so may take some time, but at least you will find out if the collation is the issue.)

|||

Hi Nitin, ManiD & Arnie,

Thanks for advise abd i found a space character at the end of the strings.

I think i better trim before kicking them into the database :)

Cheers,

Stard

|||

I don't think that shouldn't be a problem if you are doing equality in most situations:

select case when 'fred' = 'fred ' then 'Yes' Else 'No' end

Will likely return Yes. What is the collation of your database?

select databasepropertyex(db_name(),'Collation')

Monday, February 20, 2012

Problem inserting decimal data

Hi all,
I have a number of columns in an SQL server table that are of type Decimal.
The problem is, when I create a stored procedure and add decimal data to the
table, the decimal places are chopped off. The number of decimal places to
be stored is set to auto, so that should be ok.
Does anyone know what would cause this?
Thanks to anyone who can help
SimonSimon
Can you show us your INSERT statement?
CREATE TABLE #Test
(
col DECIMAL (18,2)
)
GO
INSERT INTO #Test VALUES (12.5)
INSERT INTO #Test VALUES (10.55)
INSERT INTO #Test VALUES (8.99)
GO
SELECT * FROM #Test
"Simon Harvey" <sh856531@.microsofts_free_email_service.com> wrote in message
news:ueWav8PMEHA.808@.tk2msftngp13.phx.gbl...
> Hi all,
> I have a number of columns in an SQL server table that are of type
Decimal.
> The problem is, when I create a stored procedure and add decimal data to
the
> table, the decimal places are chopped off. The number of decimal places to
> be stored is set to auto, so that should be ok.
> Does anyone know what would cause this?
> Thanks to anyone who can help
> Simon
>

Problem inserting decimal data

Hi all,
I have a number of columns in an SQL server table that are of type Decimal.
The problem is, when I create a stored procedure and add decimal data to the
table, the decimal places are chopped off. The number of decimal places to
be stored is set to auto, so that should be ok.
Does anyone know what would cause this?
Thanks to anyone who can help
Simon
Simon
Can you show us your INSERT statement?
CREATE TABLE #Test
(
col DECIMAL (18,2)
)
GO
INSERT INTO #Test VALUES (12.5)
INSERT INTO #Test VALUES (10.55)
INSERT INTO #Test VALUES (8.99)
GO
SELECT * FROM #Test
"Simon Harvey" <sh856531@.microsofts_free_email_service.com> wrote in message
news:ueWav8PMEHA.808@.tk2msftngp13.phx.gbl...
> Hi all,
> I have a number of columns in an SQL server table that are of type
Decimal.
> The problem is, when I create a stored procedure and add decimal data to
the
> table, the decimal places are chopped off. The number of decimal places to
> be stored is set to auto, so that should be ok.
> Does anyone know what would cause this?
> Thanks to anyone who can help
> Simon
>

Problem inserting decimal data

Hi all,
I have a number of columns in an SQL server table that are of type Decimal.
The problem is, when I create a stored procedure and add decimal data to the
table, the decimal places are chopped off. The number of decimal places to
be stored is set to auto, so that should be ok.
Does anyone know what would cause this?
Thanks to anyone who can help
SimonSimon
Can you show us your INSERT statement?
CREATE TABLE #Test
(
col DECIMAL (18,2)
)
GO
INSERT INTO #Test VALUES (12.5)
INSERT INTO #Test VALUES (10.55)
INSERT INTO #Test VALUES (8.99)
GO
SELECT * FROM #Test
"Simon Harvey" <sh856531@.microsofts_free_email_service.com> wrote in message
news:ueWav8PMEHA.808@.tk2msftngp13.phx.gbl...
> Hi all,
> I have a number of columns in an SQL server table that are of type
Decimal.
> The problem is, when I create a stored procedure and add decimal data to
the
> table, the decimal places are chopped off. The number of decimal places to
> be stored is set to auto, so that should be ok.
> Does anyone know what would cause this?
> Thanks to anyone who can help
> Simon
>