Showing posts with label columns. Show all posts
Showing posts with label columns. Show all posts

Thursday, March 29, 2012

Error when updating bigint columns using ADO

I am attempting to write a conversion of our product for Compact Edition; we already provide it based on SQL Server. The database interface uses ADO through a Python-win32com adaptor, and has worked fine so far. (Note: *not* ADO.net, just plain old COM)

Now, a curious thing happens. When inserting new data through a Recordset, everything works fine - except for columns defined as bigint. There are no exceptions thrown, but when you read the columns back they contain nothing but zeroes. Do the same to any other column type - I've tried integer, numeric, float, nvarchar and ntext so far, and they all seem to work just fine. It does not seem to be conversion-related either, since I've tested the exact same data to various column types. And using bigint on regular SQL Server works just fine.

The code involved is quite unspectacular, and simply switching the column types to integer would solve the immediate problem, but causes potential future issues since we normally store internal IDs in bigint columns, and the values may grow quite large.
This may indicate a problem with compatibility betweeen the 3rd party python ADO adaptor and the SQL CE OLEDB provider.

Monday, March 12, 2012

Error when checking if column exists before running query.

I am getting this error when the below query is run "Invalid column
name 'CellPhone'"
if exists (select * from information_schema.columns where table_name
='Customers' AND COLUMN_NAME = 'CellPhone')
UPDATE Customers SET PhoneNumber = CellPhone
GO
The Customers table exists but the column CellPhone doesn't.
SQL seems to try to validate the update query even if its not going to
be run.
If I change the table to something that doesn't exist, it will skip
over the line without any errors.
eg. UPDATE CustomersXXX SET PhoneNumber = CellPhone
So if the table does exist it must try to validate the columns against
the table.
Any ideas on how to get around this? I don't want it to run the query
if the column doesn't exist.
ThanksThere might be better ways but this splits the statement into two compiles:
if exists (select * from information_schema.columns where table_name
='Customers' AND COLUMN_NAME = 'CellPhone')
EXEC ('UPDATE Customers SET PhoneNumber = CellPhone')
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
<focus.nz@.gmail.com> wrote in message
news:1151547434.570100.97390@.m73g2000cwd.googlegroups.com...
>I am getting this error when the below query is run "Invalid column
> name 'CellPhone'"
>
> if exists (select * from information_schema.columns where table_name
> ='Customers' AND COLUMN_NAME = 'CellPhone')
> UPDATE Customers SET PhoneNumber = CellPhone
> GO
>
> The Customers table exists but the column CellPhone doesn't.
> SQL seems to try to validate the update query even if its not going to
> be run.
> If I change the table to something that doesn't exist, it will skip
> over the line without any errors.
> eg. UPDATE CustomersXXX SET PhoneNumber = CellPhone
> So if the table does exist it must try to validate the columns against
> the table.
> Any ideas on how to get around this? I don't want it to run the query
> if the column doesn't exist.
> Thanks
>|||There might be better ways but this splits the statement into two compiles:
if exists (select * from information_schema.columns where table_name
='Customers' AND COLUMN_NAME = 'CellPhone')
EXEC ('UPDATE Customers SET PhoneNumber = CellPhone')
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
<focus.nz@.gmail.com> wrote in message
news:1151547434.570100.97390@.m73g2000cwd.googlegroups.com...
>I am getting this error when the below query is run "Invalid column
> name 'CellPhone'"
>
> if exists (select * from information_schema.columns where table_name
> ='Customers' AND COLUMN_NAME = 'CellPhone')
> UPDATE Customers SET PhoneNumber = CellPhone
> GO
>
> The Customers table exists but the column CellPhone doesn't.
> SQL seems to try to validate the update query even if its not going to
> be run.
> If I change the table to something that doesn't exist, it will skip
> over the line without any errors.
> eg. UPDATE CustomersXXX SET PhoneNumber = CellPhone
> So if the table does exist it must try to validate the columns against
> the table.
> Any ideas on how to get around this? I don't want it to run the query
> if the column doesn't exist.
> Thanks
>|||Thanks, that did the trick.

Error when checking if column exists before running query.

I am getting this error when the below query is run "Invalid column
name 'CellPhone'"
if exists (select * from information_schema.columns where table_name
='Customers' AND COLUMN_NAME = 'CellPhone')
UPDATE Customers SET PhoneNumber = CellPhone
GO
The Customers table exists but the column CellPhone doesn't.
SQL seems to try to validate the update query even if its not going to
be run.
If I change the table to something that doesn't exist, it will skip
over the line without any errors.
eg. UPDATE CustomersXXX SET PhoneNumber = CellPhone
So if the table does exist it must try to validate the columns against
the table.
Any ideas on how to get around this? I don't want it to run the query
if the column doesn't exist.
ThanksThere might be better ways but this splits the statement into two compiles:
if exists (select * from information_schema.columns where table_name
='Customers' AND COLUMN_NAME = 'CellPhone')
EXEC ('UPDATE Customers SET PhoneNumber = CellPhone')
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
<focus.nz@.gmail.com> wrote in message
news:1151547434.570100.97390@.m73g2000cwd.googlegroups.com...
>I am getting this error when the below query is run "Invalid column
> name 'CellPhone'"
>
> if exists (select * from information_schema.columns where table_name
> ='Customers' AND COLUMN_NAME = 'CellPhone')
> UPDATE Customers SET PhoneNumber = CellPhone
> GO
>
> The Customers table exists but the column CellPhone doesn't.
> SQL seems to try to validate the update query even if its not going to
> be run.
> If I change the table to something that doesn't exist, it will skip
> over the line without any errors.
> eg. UPDATE CustomersXXX SET PhoneNumber = CellPhone
> So if the table does exist it must try to validate the columns against
> the table.
> Any ideas on how to get around this? I don't want it to run the query
> if the column doesn't exist.
> Thanks
>|||Thanks, that did the trick.

Friday, March 9, 2012

Error when alternating background color in table rows

Hi All,

I have a table containing 21 columns. I want to alternate the color on the rows, to make it more radable and nocer to the eye. As such I set the BackgroundColor property on the entire TableRow (so it is applied to every textbox) to the following:

Code Snippet

=iif(RowNumber(nothing)Mod 2,"LightGray","White")

In theory it should work. I checked a few of the texboxes to make sure everything was okay and indeed the BackgroundColor property on each one of them was properly set to the above expression.

When I tried to build the report, I was prompted by 21 errors (one per textbox) stating the following:

[rsCompilerErrorInExpression] The BackgroundColor expression for the textbox 'FIELDNAME' contains an error: [BC30455] Argument not specified for parameter 'TruePart' of 'Public Function IIf(Expression As Boolean, TruePart As Object, FalsePart As Object) As Object'.

Obviously the TruePart parameter has been specified ("LightGray" in my expression), so what could be wrong?

Thanks in advance for the help

Idelso

Hello,

Your function is good. Check the spelling of "LightGray". Try "LightGrey".

Regards...|||

Hi asiaindian,

Unfortunately that didnt do the trick. This time around a went with much simpler, one word, color names and still nothing.

The error messages keep popping up.

Code Snippet

=iif(RowNumber(nothing)Mod 2,"Silver","White")

Thanks,

Idelso

|||

Well, I found the solution to the problem, for those of you who might have to face it in the future....it is a very simple fix.

Amazing what a great "compiler" SSRS has (I am being sarcastic for the record).

It so happens that you can enter the expression as previously shown without the system indicating any syntax problem with it. Well, we are wrong, the only way this is going to be built is if you keep a space between your RowNumber function call and the "Mod" call. So the correct format is:

Code Snippet

=iif(RowNumber(nothing) Mod 2, "Silver","White")

(Pay attention to the space between (nothing) and Mod)

Yup, this was the problem.....interesting

Idelso

Friday, February 17, 2012

error selecting null columns

I want to run a query that selects rows from the table where a datetime column has null values;

select*from OrderswhereIsNull(dClosedDate,'Null')='Null'

However i get this error:

Conversion failed when converting datetime from character string.

Any help appreciated

SELECT * FROM Orders WHERE ISNULL(dClosedDate, '1900-01-01') = '1900-01-01'

|||

thx...i tried dClosedDate is NULL and it worked too.

Error selecting data due to floating pt exception

Got a good one! or a bad one depending if the boss is breathing down the neck.

I am selecting from a table. When certain columns are selected, sql server generates the following message:

[Microsoft][ODBC SQL Server Driver]Numeric value out of range

To be more specific, if i select the id column of the table I get perhaps 4 rows.

select id from table
1
2
3
4

If I select the id column plus the column causing problems, then I only see the rows that don't generate the message, plus i get the above listed message

select id, columnThatIsFloat from table
1

In fact there are 4 columns in the table that are generating these messages. All of which are of type Float.

If I try to convert the column I get the following error:
Server: Msg 3628, Level 16, State 1, Line 1
A floating point exception occurred in the user process. Current transaction is canceled.

What could cause this. Bad data? How could it have been inputted? Is this a bug with SQL 2k? Why me?

SQL information:
Microsoft SQL Server 2000 - 8.00.384 (Intel X86) May 23 2001 00:02:52 Copyright (c) 1988-2000 Microsoft Corporation Standard Edition on Windows NT 5.0 (Build 2195: Service Pack 4)Are you aggregating any of the columns ? Have you run dbcc checktable or dbreindex ?|||Which service pack do you have installed for sql server ?|||I am doing no aggregation. It truely is as simple as

select colA, colB from table

SQL information:
Microsoft SQL Server 2000 - 8.00.384 (Intel X86) May 23 2001 00:02:52 Copyright (c) 1988-2000 Microsoft Corporation Standard Edition on Windows NT 5.0 (Build 2195: Service Pack 4)

Originally posted by rnealejr
Which service pack do you have installed for sql server ?|||The problem with posting SQL Server 2000 - 8.00.384 it does not tell you what service pack sql server has installed. In your case you have sp1 installed. I would recommend that you update your service pack.

Also, have you run the dbcc commands ?|||Hello,

I am not aggregating columns (see the previous message) and I have run dbcc checktable with the following result:

DBCC results for 'TABLENAME'.
There are 5218 rows in 62 pages for object 'TABLENAME'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

I do not know what "dbreindex" is.

Thanks
Josh

Originally posted by rnealejr
Are you aggregating any of the columns ? Have you run dbcc checktable or dbreindex ?|||There is a bug with the indexing wizard that is corrected when you update the service pack that causes similar issues that you are experiencing. dbcc dbreindex rebuilds an index for a table.|||I've now upgraded to sp3a. I was looking at the service pack for the Win2K server. My oversight. Unfortunately I am still having the exact same problem.

Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05 Copyright (c) 1988-2003 Microsoft Corporation Standard Edition
on Windows NT 5.0 (Build 2195: Service Pack 4)

i did run "dbcc checktable" and "dbcc dbreindex"

If you have any more ideas I would greatly appreciate.

Thanks alot

Originally posted by rnealejr
The problem with posting SQL Server 2000 - 8.00.384 it does not tell you what service pack sql server has installed. In your case you have sp1 installed. I would recommend that you update your service pack.

Also, have you run the dbcc commands ?