Showing posts with label null. Show all posts
Showing posts with label null. Show all posts

Monday, March 26, 2012

Error Including null value in a Numeric field

Hi All,

I'm migrating some SQL 2000 DTS to SSIS.

I am transfering data from a DB2 table to a SQL 2005 table using the OLE DB Source, Data Converstion then the OLE DB Destionation.

So, I have a numeric (Precision 3, Scale 2) field with NULL value in the DB2 table.

I'm trying to transfer these data to a SQL2005 table and I am receiving this error message below:

"[Destination Table TFACIL [18]] Error: There was an error with input column "COMB_OPPT_PRCT" (2865) on input "OLE DB Destination Input" (31). The column status returned was: "The value violated the integrity constraints for the column.". "

The field must accept null because of the APPLICATION ( i can't change it, im not the owner ).

Could someone help me?

Thanks in advance.

Regards,

Thiago

Check that the SQL table TFACIL.COMB_OPPT_PRCT

1) Has no CHECK constraints on it that would prevent NULL being loaded

2) is not defined as NOT NULL

Sunday, March 11, 2012

Error in Reading Float data

I am using SQL Server 2000, VS 2003

I have Education table in which there is a field CGPA having float data type (null allowed) I retreive the data from SQL server using stroed proc and store it in SqlDataReader dr while reading if CGPA contains 0 then it raises an error that "Specified cast is not valid" other wise it does not raise any error.

while (dr.Read())
{
Education e = new Education();
e.EducationId = dr.GetInt32(0);
e.Country = dr.GetInt32(1);
e.InstitutionName = dr.GetString(2);
e.Grade = dr.GetString(3);
e.CGPA = dr.GetFloat(4); // ERROR HERE
e.Percentage = dr.GetFloat(5);
e.PassingYear = dr.GetString(6);
}

where as in Education CGPA is also the float property can any one tell me how to read 0 value of float from SQL server

GPA can be handled with Decimal or Numric data type, there are some tasks like complex calculus that require Float data type because the T-SQL functions are in Float but student grade is simple Arithmetic so you can use Decimal instead of Float. The reason Float is very unstable, long time SQL Server users use it for calculations but convert the value to Decimal for storage because you can set precision and scale with Decimal. Hope this helps.|||

Avoid floats, reals, single, doubles if at all possible in the database. They are imprecise numbers and well... They cause all kinds of weird issues. It's not SQL Server issues, it's just issues with those data types in general.

That said, I don't see how it's causing your problem. If you know the column names of the record format, try:

e.CGPA=dr("CGPA")

That assumes the field/column is named CGPA of course.

Or try:

Dim o as object
o=dr("CGPA")
e.CGPA=o

that way you can see what "o" is before you try and convert it to whatever type e.CGPA is.

|||Another option is a simple ANSI ALTER TABLE to change FLOAT to DECIMAL. Run a search for ALTER TABLE in SQL Server BOL (books online). Hope this helps.

Error in my 8 table SQL Script

/*Script Start*/

create database HorizonAirways

create table Sector
(
SectorID Char(5) constraint SectorID primary key clustered not null,
Description VarChar(50) not null,
WeekDay1 char(3) not null,
WeekDay2 char(3) not null,
FirstClassFare Money not null,
BusinessClassFare Money not null,
EconomyClassFare Money not null
)

select * from Sector

create table Aircraft
(
AircraftTypeID char(4) constraint AircraftTypeID primary key clustered not null,
Description char(30) not null,
FirstClassSeats int not null,
BusinessClassSeats int not null,
EconomyClassSeats int not null
)
select * from Aircraft

create table flights
(
FlightNo char(5) constraint FlightNo primary key clustered not null,
DepTime char(5) not null,
ArrTime char(5) not null,
AircraftTypeID char(4) references Aircraft(AircraftTypeID) not null,
SectorID Char(5) references Sector(SectorID) not null
)

select * from Flights

create table ScheduledFlights
(
FlightNo char(5) references flights(FlightNo) not null,
FlightDate datetime not null,
FirstClassSeatsAvailable int not null,
BusinessClassSeatsAvailable int not null,
EconomyClassSeatsAvailable int not null
)

select * from ScheduledFlights

create table passenger
(
PnrNo char(8) constraint PNR primary key clustered not null,
FlightNo char(5) references flights(FlightNo) not null,

TravelDate datetime constraint PassengerFlights Foreign key (FlightNo, DeptTime) references flights (FlightNo,DepTime) not null,

FName char(20) not null,
LName char(20) not null,
Age int not null,
Gender char(1) not null,
Class char(15) not null,
SeatPref char(6) not null,
MealPref char(15) not null,
SSR varchar(100) not null,
Status char(15)
)

create table DailyCollection
(
PnrNo char(8) references Passenger(PnrNo) not null,
TransDate Datetime not null,
TranType Char(1) not null,
Amount Float not null
)

create table users
(
UserName char(15) constraint Username primary key clustered not null,
Password char(15) not null,
UserRole Char(15) not null
)

!!OUTPUT!!

--
Msg 8140, Level 16, State 0, Line 48
More than one key specified in column level FOREIGN KEY constraint, table 'passenger'.
Msg 1769, Level 16, State 1, Line 48
Foreign key 'PassengerFlights' references invalid column 'DeptTime' in referencing table 'passenger'.
Msg 1750, Level 16, State 0, Line 48
Could not create constraint. See previous errors.
--

--
In the project given by our teacher it says about Passenger Table
Pnr(PK)- Char (8) no null values

FlightNo- Char(5) no null values

TravelDate- DateTime no null values
info-Date of travel. The flight number and the date of travel together gorm a foreign key that references the flight number and the flight date in theFlight Table.
--
rest is fine.....

CAN ANYONE PLEASE RECTIFY THESE ERRORS ?
There are some typos in your script as well as problem with contraints. My preferable way to define constraints is to use separate statements instead of inline within the table creation script. I addition you can only reference primary keys (one or more column as a combound key) with a foreign key constraint. So you will either have to extend the primary key in the flights table to the DeptTime ot narrow the foreign key on the passenger table to flightNo only. As of my knowledge about flight it has to be the first solution, right ? :-)

create table passenger

(

PnrNo char(8) constraint PNR primary key clustered not null,

FlightNo char(5) not null,

FName char(20) not null,

LName char(20) not null,

Age int not null,

Gender char(1) not null,

Class char(15) not null,

SeatPref char(6) not null,

MealPref char(15) not null,

SSR varchar(100) not null,

Status char(15),

TravelDate datetime

)

ALTER TABLE Passenger

ADD CONSTRAINT FK_Passenger_Flights FOREIGN KEY (FlightNo, TravelDate)

references flights(FlightNo, DepTime)

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||Thank you very much.

In future i will use your way. I will define constraints separately. Cheers !!
|||Great reply and its works..

Error in my 8 table SQL Script

/*Script Start*/

create database HorizonAirways

create table Sector
(
SectorID Char(5) constraint SectorID primary key clustered not null,
Description VarChar(50) not null,
WeekDay1 char(3) not null,
WeekDay2 char(3) not null,
FirstClassFare Money not null,
BusinessClassFare Money not null,
EconomyClassFare Money not null
)

select * from Sector

create table Aircraft
(
AircraftTypeID char(4) constraint AircraftTypeID primary key clustered not null,
Description char(30) not null,
FirstClassSeats int not null,
BusinessClassSeats int not null,
EconomyClassSeats int not null
)
select * from Aircraft

create table flights
(
FlightNo char(5) constraint FlightNo primary key clustered not null,
DepTime char(5) not null,
ArrTime char(5) not null,
AircraftTypeID char(4) references Aircraft(AircraftTypeID) not null,
SectorID Char(5) references Sector(SectorID) not null
)

select * from Flights

create table ScheduledFlights
(
FlightNo char(5) references flights(FlightNo) not null,
FlightDate datetime not null,
FirstClassSeatsAvailable int not null,
BusinessClassSeatsAvailable int not null,
EconomyClassSeatsAvailable int not null
)

select * from ScheduledFlights

create table passenger
(
PnrNo char(8) constraint PNR primary key clustered not null,
FlightNo char(5) references flights(FlightNo) not null,

TravelDate datetime constraint PassengerFlights Foreign key (FlightNo, DeptTime) references flights (FlightNo,DepTime) not null,

FName char(20) not null,
LName char(20) not null,
Age int not null,
Gender char(1) not null,
Class char(15) not null,
SeatPref char(6) not null,
MealPref char(15) not null,
SSR varchar(100) not null,
Status char(15)
)

create table DailyCollection
(
PnrNo char(8) references Passenger(PnrNo) not null,
TransDate Datetime not null,
TranType Char(1) not null,
Amount Float not null
)

create table users
(
UserName char(15) constraint Username primary key clustered not null,
Password char(15) not null,
UserRole Char(15) not null
)

!!OUTPUT!!

--
Msg 8140, Level 16, State 0, Line 48
More than one key specified in column level FOREIGN KEY constraint, table 'passenger'.
Msg 1769, Level 16, State 1, Line 48
Foreign key 'PassengerFlights' references invalid column 'DeptTime' in referencing table 'passenger'.
Msg 1750, Level 16, State 0, Line 48
Could not create constraint. See previous errors.
--

--
In the project given by our teacher it says about Passenger Table
Pnr(PK)- Char (8) no null values

FlightNo- Char(5) no null values

TravelDate- DateTime no null values
info-Date of travel. The flight number and the date of travel together gorm a foreign key that references the flight number and the flight date in the Flight Table.
--
rest is fine.....

CAN ANYONE PLEASE RECTIFY THESE ERRORS ?There are some typos in your script as well as problem with contraints. My preferable way to define constraints is to use separate statements instead of inline within the table creation script. I addition you can only reference primary keys (one or more column as a combound key) with a foreign key constraint. So you will either have to extend the primary key in the flights table to the DeptTime ot narrow the foreign key on the passenger table to flightNo only. As of my knowledge about flight it has to be the first solution, right ? :-)

create table passenger

(

PnrNo char(8) constraint PNR primary key clustered not null,

FlightNo char(5) not null,

FName char(20) not null,

LName char(20) not null,

Age int not null,

Gender char(1) not null,

Class char(15) not null,

SeatPref char(6) not null,

MealPref char(15) not null,

SSR varchar(100) not null,

Status char(15),

TravelDate datetime

)

ALTER TABLE Passenger

ADD CONSTRAINT FK_Passenger_Flights FOREIGN KEY (FlightNo, TravelDate)

references flights(FlightNo, DepTime)

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||Thank you very much.

In future i will use your way. I will define constraints separately. Cheers !!|||Great reply and its works..

Wednesday, March 7, 2012

error in image field when using CASE statement

I've this Stored procedure on a SQLserver 2000 SP3:

SELECT *,CASE immagine WHEN NULL THEN 0 ELSE 1 END AS hasImage
FROM Squadre WHERE squadra = @.squadra

this is a flag that returns if the image field is present or not..
i've a lot of this type of stored procedures.. but this one returns me an error..

--------
Microsoft SQL-DMO (ODBC SQLState: 42000)
--------
Errore 306: The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.
--------
OK
--------

An i can't save.. why?
reme,ber that in the same Db there's other Stored like this.. the same syntax and the same field or table.. can anyone help me??So, are you saying that "sometimes" it works and sometimes it doesn't?

This should work "always":

SELECT *,CASE WHEN immagine IS NULL THEN 0 ELSE 1 END AS hasImage
FROM Squadre WHERE squadra = @.squadra

But exclude the image field from the SELECT list, unless you really intend to use it.|||i must use it!!!

Sunday, February 19, 2012

Error in a Sinmple Function

Hi,
I am using the following Code in the Report Properties. This function
displays the manufactuere logo when brand parameter is null and when brand
is not null it should display the brand logo.
Function ImageDisp(byVal a as String)as String
Select Case a
case ""
return
"https://192.168.1.16/dev/ReportsImages/"&First(Fields!IMAGEORIG.Value,
"DataSet1");
case else
return
"https://192.168.1.16/dev/ReportsImages/"&First(Fields!BrandLogo.Value,
"DataSet1");
End Select
End Function
In Image2 value is put =Code.ImageDisp(Parameters!Brand.Value) . Now the
problem is that on previewing I am getting the error "There is an error in
line 33 of custom code. Name First is not declared."
Any help is appreciated.
Thanks
--
pmudI believe when the custom code is executed, you cannot refer to fields in the
dataset or use RDL functions. You will have to add a parameter to your
function to pass in the FIRST(Field) value.
"pmud" wrote:
> Hi,
> I am using the following Code in the Report Properties. This function
> displays the manufactuere logo when brand parameter is null and when brand
> is not null it should display the brand logo.
> Function ImageDisp(byVal a as String)as String
> Select Case a
> case ""
> return
> "https://192.168.1.16/dev/ReportsImages/"&First(Fields!IMAGEORIG.Value,
> "DataSet1");
> case else
> return
> "https://192.168.1.16/dev/ReportsImages/"&First(Fields!BrandLogo.Value,
> "DataSet1");
> End Select
> End Function
> In Image2 value is put =Code.ImageDisp(Parameters!Brand.Value) . Now the
> problem is that on previewing I am getting the error "There is an error in
> line 33 of custom code. Name First is not declared."
> Any help is appreciated.
> Thanks
> --
> pmud