Sql 2000: Does Float Column Allow 0 When Allow Null=false
Oct 11, 2007
Hi,
I have a float column with Allow Nulls= false
Is it normal that when I try to set the column to 0, i get the error:
Cannot insert duplicate key in object
Please note that the column is part of a primary key and that there is no record with the value of the column 0 in the table in question.
Thank you.
View 5 Replies
ADVERTISEMENT
May 25, 2006
I am using Naive Bayes, Decision Trees, and Neural Net (SSAS 2005) to predict which of two states each record belongs to.
How can I enforce a different penalty for a false positive versus a false negative ? (I am assuming that in some sense the mining algorithms can then minimize the total penalty).
View 5 Replies
View Related
Apr 29, 2008
the Table columns is like this NO ProductNo Area In Out1 0001 US NULL NULL2 0002 UK NULL Y3 0003 FR Y NULL 4 0004 FR Y NULL5 0005 UK Y NULL I have Query get the result belowArea Count In&OutUS 1UK 2FR 2 the Area is Group By by Area and the Count columns is counting how many recoreds Table for each Areathe problem is the column "In & OUt'I have to make sure if the "In" or "Out" is Null , if one of them is Null the plus 1 so the result would like I have Query get the result belowArea Count In&OutUS 1 1
UK 2 1
FR 2 0 which syntax I can use for the problem? I just think maybe I can use IsNULL?but I have no idea how to wirte a query ...can you give me a hint? thank you
View 4 Replies
View Related
Dec 28, 2007
Hi there, I've a question regaarding datatype conversions... I can't convert the above mentioned datatype. I always get an error message that the conversion fails. Doesn't matter If convert or cast is used.
How would you convert the above mentioned variable into float???
View 8 Replies
View Related
Sep 11, 2007
Hi, I have a matrix with 2 row groups and 1 column group.
CGroup1 Val1
CGroup1 Val2
Total
- RGroup1 Val1
RGroup2 Val1
In
In
Out
RGroup2 Val2
In
In
Out
- RGroup1 Val2
RGroup2 Val3
In
In
Out
RGroup2 Val4
In
In
Out
Total
Out
Out
Out
I want to change the row totals at the RGroup2 level. I have put an expression in the measure cell as:
=iif(InScope("matrix1_RowGroup2"), "In", "Out"). Shouldn't the values in the Totals Column on the far right evaluate to "In"? If not, how can I isolate the totals at the RGroup2 level?
Also, I found that when I put =fields!RGroup2.value in the expression for the cell, the Totals Column on the far right is blank but when I put =fields!RGroup1.value the correct value is properly displayed in the Total Column. Why does =fields!RGroup2.value not work?
View 7 Replies
View Related
Mar 20, 2008
I had database with "-1.#IND" (Indefinite /infinite) values in float columns.
Is there anyway I can insert -1#IND value into float column using some insert query and query analyzer? I am using SQL Server 2000.
I want to insert this value to replicate the issue..just for testing.I am wondring how my database got these values.
Thanks in Advance!
View 1 Replies
View Related
Feb 12, 2014
I'm using this query to sum the values. The cost column is a float datatype and what could I differently do here to sum the cost. I'm unable to sum the cost.
Also is there any way I change the datatype to int for Cost column without losing the data.
select ID, MAX(Date) Date, SUM(Cost) Cost, MAX(Funding) Funding from Application
group by ID
View 4 Replies
View Related
Dec 12, 2007
How can I remove -1.#IND values from a float column in SQL Server 2000 (8.00.2039 SP4).
So far I've tried
- Using Query Analyzer, setting the value to a proper float value. I receive error €śA floating point exception occurred€?
- Using Query Analyzer, deleting the record with the invalid float. I receive error €śA floating point exception occurred€?
- Using Enterprise Manager, setting the value to a proper float value. I receive error €śA floating point exception occurred€?
- Using Enterprise Manager, deleting the record with the invalid float. I receive error €śA floating point exception occurred€?
- Previously I was able to convert the column to nvarchar, but now this fails because the table is being replicated.
I don€™t really care what happens to the records, I just need them to go away.
Thanks
View 2 Replies
View Related
Oct 16, 2013
We sometimes have small values stored in a column with datatype of float like 0.000644470739403048 which is being converted to -5.8E-05. Perhaps that is OK to be stored in the database however I need the value in decimal format to use. (I'm using longitude values in google maps).
is there anything I can do at the database level. I was looking at the properties which is 53 numeric precision and 8 length.
View 8 Replies
View Related
Nov 8, 2007
STDEV() gives incorrect values with reasonable input.
I have a table filled with GPS readings. I've got a column LATITUDE (FLOAT) with about 20,000 records between 35.6369018 and 35.639890. (Same value to the first 5 digits of precision---what can i say, it's a good gps.)
Here's what happens when I ask SQL Server ("9.00.1399.06 (IntelX86)") to compute the standard deviation of the latitude:
// Transact-SQL StdDev function:
SELECT STDEV(LATITUDE) FROM GPSHISTORY
WHERE STATTIME BETWEEN '2007-10-23 11:21:00.859' AND '2007-10-23 17:00:00.062' AND GPSDEVICEID = 0x004A08BC04050000;
0
// Zero. ZERO??!?!!
//Let's re-implement Std Dev from the definition using other aggregate functions:
DECLARE @AVERAGE FLOAT;
SELECT @AVERAGE = AVG(LATITUDE) FROM GPSHISTORY
WHERE GPSDATE BETWEEN '2007-10-23 11:21:00.859' AND '2007-10-23 17:00:00.062' AND GPSDEVICEID = 0x004A08BC04050000;
SELECT SQRT(SUM(SQUARE((LATITUDE - @AVERAGE)))/COUNT(LATITUDE)) FROM GPSHISTORY
WHERE GPSDATE BETWEEN '2007-10-23 11:21:00.859' AND '2007-10-23 17:00:00.062' AND GPSDEVICEID = 0x004A08BC04050000;
6.03401924005392E-06
// That's better. Maybe STDEV is using fixed point arithmetic?!?
SELECT STDEV(10 * LATITUDE)/10 FROM GPSHISTORY
WHERE GPSDATE BETWEEN '2007-10-23 11:21:00.859' AND '2007-10-23 17:00:00.062' AND GPSDEVICEID = 0x004A08BC04050000;
4.77267753808509E-06
SELECT STDEV(100 * LATITUDE)/100 FROM GPSHISTORY
WHERE GPSDATE BETWEEN '2007-10-23 11:21:00.859' AND '2007-10-23 17:00:00.062' AND GPSDEVICEID = 0x004A08BC04050000;
1.66904329068838E-05
SELECT STDEV(1000 * LATITUDE)/1000 FROM GPSHISTORY
WHERE GPSDATE BETWEEN '2007-10-23 11:21:00.859' AND '2007-10-23 17:00:00.062' AND GPSDEVICEID = 0x004A08BC04050000;
8.11904280806654E-06
// The standard deviation should, of course, be linear, e.g.
DECLARE @AVERAGE FLOAT;
SELECT @AVERAGE = AVG(LATITUDE) FROM GPSHISTORY
WHERE GPSDATE BETWEEN '2007-10-23 11:21:00.859' AND '2007-10-23 17:00:00.062' AND GPSDEVICEID = 0x004A08BC04050000;
SELECT SQRT(SUM(SQUARE(100*(LATITUDE - @AVERAGE)))/COUNT(LATITUDE))/100 FROM GPSHISTORY
WHERE GPSDATE BETWEEN '2007-10-23 11:21:00.859' AND '2007-10-23 17:00:00.062' AND GPSDEVICEID = 0x004A08BC04050000;
6.03401924005389E-06
// Std Dev is a numerically stable computation, although it does require traversing the dataset twice.
//
// This calculation is not being done correctly.
//
// Incidently, SQRT(VAR(Latitude....)) gives 4.80354E-4, which is also way off.
I will redefine STDEV to use a stored procedure similar to the above, but the algorithm used to compute VAR, STDEV etc should be reviewed and fixed.
-Rob Calhoun
View 3 Replies
View Related
Jun 19, 2007
Hello,
I have a problem with the round of SQL Server 2K on the float data type.
In my application I do a SQL request for find a row in a table of SQL Server 2K.
This is the request :
SELECT DISTINCT N_ROW_ID FROM COMM WHERE N_ARTICLE_ID=79510 AND N_DATASOURCE_ID=1 AND N_SOURCE_ID=-102 AND N_PROVIDER_ID=-100
AND N_LEAD_TIME IS NULL AND N_UNIT_PRICE = 329.78 AND N_UNIT_PRICE_CURRENCY_ID=1
N_UNIT_PRICE is a float data type.
In the line need, the field N_UNIT_PRICE has 329.78 but with the round of SQL Server 2K I have 329.779999999999997.
So I never find the row
Do you have a solution for comparate a float flied with SQL Server round and a float send in a request as my 329.78?
I can't transform the column in decimal or numeric data type.
Is it possible to Disable the function?
Regards
View 2 Replies
View Related
Apr 9, 2007
I can't take full credit for this. I want to share this with Jeff Moden who did the important research for this calculation here.
All I did was just adapting some old code according to the mantissa finding Jeff made and optimized it a little
Some test codeDECLARE@SomeNumber FLOAT,
@BinFloat BINARY(8)
SELECT@SomeNumber = -185.6125,
@BinFloat = CAST(@SomeNumber AS BINARY(8))
SELECT@SomeNumber AS [Original],
CAST(@SomeNumber AS BINARY(8)) AS [Binary],
dbo.fnBinaryFloat2Float(CAST(@SomeNumber AS BINARY(8))) AS [Converted],
@SomeNumber - dbo.fnBinaryFloat2Float(CAST(@SomeNumber AS BINARY(8))) AS [Error]
And here is the code for the function.CREATE FUNCTION dbo.fnBinaryFloat2Float
(
@BinaryFloat BINARY(8)
)
RETURNS FLOAT
AS
BEGIN
DECLARE@Part TINYINT,
@PartValue TINYINT,
@Mask TINYINT,
@Mantissa FLOAT,
@Exponent SMALLINT,
@Bit TINYINT,
@Ln2 FLOAT,
@BigValue BIGINT
SELECT@Part = 1,
@Mantissa = 1,
@Bit = 1,
@Ln2 = LOG(2),
@BigValue = CAST(@BinaryFloat AS BIGINT),
@Exponent = (@BigValue & 0x7ff0000000000000) / EXP(52 * @Ln2)
WHILE @Part <= 8
BEGIN
SELECT@Part = @Part + 1,
@PartValue = CAST(SUBSTRING(@BinaryFloat, @Part, 1) AS TINYINT),
@Mask =CASE WHEN @Part = 2 THEN 8 ELSE 128 END
WHILE @Mask > 0
BEGIN
IF @PartValue & @Mask > 0
SET @Mantissa = @Mantissa + EXP(-@Bit * @Ln2)
SELECT@Bit = @Bit + 1,
@Mask = @Mask / 2
END
END
RETURNSIGN(@BigValue) * @Mantissa * POWER(CAST(2 AS FLOAT), @Exponent - 1023)
END
Thanks again Jeff!
Peter Larsson
Helsingborg, Sweden
View 3 Replies
View Related
Sep 10, 2007
Hi,
I have a excel file which i want to import the data to sql server... The sql server Data type for that particular column is
varchar and it has a contraint too like the data should be in this fashion 00000-0000 or 00000...
but when i try to import the data from the excel to sql server... 08545 just becomes 8545 (cause excel is treating it as a float) and so my insert fails...
what can i do to rectify the problem...
regards
Karen
View 8 Replies
View Related
Apr 2, 2007
I am getting this error: "Cannot insert the value NULL into column 'OrderID', table 'outman.outman.Contact'; column does not allow nulls. INSERT fails." -- But my value is not null. I did a response.write on it and it show the value. Of course, it would be nice if I could do a breakpoint but that doesn't seem to be working. I'll attach a couple of images below of my code, the error, and the breakpoint error.
Server Error in '/' Application.
Cannot insert the value NULL into column 'OrderID', table 'outman.outman.Contact'; column does not allow nulls. INSERT fails.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'OrderID', table 'outman.outman.Contact'; column does not allow nulls. INSERT fails.Source Error:
Line 89: sContact.Phone = sPhone.Text.Trim
Line 90: sContact.Email = sEmail.Text.Trim
Line 91: sContact.Save()
Line 92:
Line 93: Dim bContact As Contact = New Contact()Source File: F:InetpubwwwrootOutman KnifeCheckout.aspx.vb Line: 91 Stack Trace:
[SqlException (0x80131904): Cannot insert the value NULL into column 'OrderID', table 'outman.outman.Contact'; column does not allow nulls. INSERT fails.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857354
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734966
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
System.Data.SqlClient.SqlDataReader.HasMoreRows() +150
System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean setTimeout) +214
System.Data.SqlClient.SqlDataReader.Read() +9
System.Data.SqlClient.SqlCommand.CompleteExecuteScalar(SqlDataReader ds, Boolean returnSqlValue) +39
System.Data.SqlClient.SqlCommand.ExecuteScalar() +148
SubSonic.SqlDataProvider.ExecuteScalar(QueryCommand qry) +209
SubSonic.DataService.ExecuteScalar(QueryCommand cmd) +37
SubSonic.ActiveRecord`1.Save(String userName) +120
SubSonic.ActiveRecord`1.Save() +31
Checkout.btnCheckout_Click(Object sender, EventArgs e) in F:InetpubwwwrootOutman KnifeCheckout.aspx.vb:91
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
View 8 Replies
View Related
May 13, 2015
It's giving me an error while I'm trying to change column value from not null to null..
'tblid' table
- Unable to modify table. Â
Cannot insert the value NULL into column 'ValidID', table 'Xe01.dbo.Tmp_tblid'; column does not allow nulls. INSERT fails.
The statement has been terminated.
View 4 Replies
View Related
Apr 27, 2007
Dear folks,
please tell me the query for altering a column from not null to null
Vinod
View 15 Replies
View Related
Feb 28, 2008
Hi all,
One of my columns is the table has some Null values, and I Would like to stop having NULL values into that column any more.
I know, If I alter the column to NOT NULL will throw me an error, since it does a batch update.
Is there any way to achieve this...
Thanks...
View 3 Replies
View Related
Feb 29, 2008
Hi all,
One of my columns is the table has some Null values, and I Would like to stop having NULL values into that column any more.
I know, If I alter the column to NOT NULL will throw me an error, since it does a batch update.
Is there any way to achieve this...
Thanks...
View 3 Replies
View Related
Sep 30, 2014
We have a database where many tables have a field that has to be lengthened. In some cases this is a primary key or part of a primary key. The table in question is:-
/****** Object: Table [dbo].[DTb_HWSQueueMonthEnd] Script Date: 09/25/2014 14:05:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[DTb_HWSQueueMonthEnd](
[Code] ....
The script I am using is
DECLARE@Column varchar(100)--The name of the column to change
DECLARE@size varchar(5)--The new size of the column
DECLARE @TSQL varchar(255)--Contains the code to be executed
DECLARE @Object varchar(50)--Holds the name of the table
DECLARE @dropc varchar(255)-- Drop constraint script
[Code] ....
When I the the script I get the error message Could not create constraint. See previous errors.
Looking at the strings I build
ALTER TABLE [dbo].[DTb_HWSQueueMonthEnd] DROP CONSTRAINT PK_DTb_HWSQueueMonthEnd
ALTER TABLE [dbo].[DTb_HWSQueueMonthEnd] Alter Column [Patient System Number] varchar(10)
ALTER TABLE [dbo].[DTb_HWSQueueMonthEnd] ADD CONSTRAINT PK_DTb_HWSQueueMonthEnd PRIMARY KEY NONCLUSTERED ([Patient System Number] ASC,[Episode Number] ASC,[CensusDate] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
They all seem fine except the last one which returns the error
Msg 8111, Level 16, State 1, Line 1
Cannot define PRIMARY KEY constraint on nullable column in table 'DTb_HWSQueueMonthEnd'.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.
None of the fields I try to create the key on are nullable.
View 2 Replies
View Related
May 3, 2007
I receive this message when I try to run any report. The reportserver and reportservertempdb databases were upgraded using backup/restore from SQL2000 to SQL2005 on a separate server which is running RS2005 . Please help. Thanks
View 1 Replies
View Related
Apr 4, 2008
I have a flat file from which I am attempting to import a column that contains either float numbers or " "(single blank).
I get the following Report:
quote:
- Executing (Error)
Messages
* Error 0xc02020a1: Data Flow Task: Data conversion failed. The data conversion for column "ADR_SH_PER_ADR " returned status value 2 and status text "The value could not be converted because of a potential loss of data.".
(SQL Server Import and Export Wizard)
* Error 0xc0209029: Data Flow Task: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "output column "ADR_SH_PER_ADR " (438)" failed because error code 0xC0209084 occurred, and the error row disposition on "output column "ADR_SH_PER_ADR " (438)" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure.
(SQL Server Import and Export Wizard)
* Error 0xc0202092: Data Flow Task: An error occurred while processing file "F:WorkValMaster_Reference_Databasehs_1.txt" on data row 2.
(SQL Server Import and Export Wizard)
* Error 0xc0047038: Data Flow Task: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on component "Source - hs_1_txt" (1) returned error code 0xC0202092. The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. There may be error messages posted before this with more information about the failure.
(SQL Server Import and Export Wizard)
* Error 0xc0047021: Data Flow Task: SSIS Error Code DTS_E_THREADFAILED. Thread "SourceThread0" has exited with error code 0xC0047038. There may be error messages posted before this with more information on why the thread has exited.
(SQL Server Import and Export Wizard)
* Error 0xc0047039: Data Flow Task: SSIS Error Code DTS_E_THREADCANCELLED. Thread "WorkThread0" received a shutdown signal and is terminating. The user requested a shutdown, or an error in another thread is causing the pipeline to shutdown. There may be error messages posted before this with more information on why the thread was cancelled.
(SQL Server Import and Export Wizard)
* Error 0xc0047021: Data Flow Task: SSIS Error Code DTS_E_THREADFAILED. Thread "WorkThread0" has exited with error code 0xC0047039. There may be error messages posted before this with more information on why the thread has exited.
(SQL Server Import and Export Wizard)
Now, the strange thing is, as soon as I import the same column from an Excel file in which, for simplicity of "text to Excel" transfer I have all the columns defined as "text"(I have 170 columns), the import works just fine. The Excel file is just a straight out import into Excel of the flat file.
The only difference I see between the flat file and the Excel file is that an empty value in the flat file contains a single blank, while an empty "cell" in Excel contains nothing(cursor doesn't go to the right after clicking inside the cell).
By the way, the column in the SQL table is nullable, which is why I thought there should be no issues from an import value containing blanks exclusively.
View 7 Replies
View Related
Sep 3, 2015
I have an SSIS package that imports data from an Excel file, replaces any value in Excel that reads "NULL" to "", then writes the data to a couple of databases.
What I have discovered today, is I have two columns of dates, an admit date and discharge date column, and what I need to do is anywhere I have a null value in the discharge date column, I have to replace it with the value in the admit date column.Â
I have searched around online and tried a few things using the Replace funtion in Derived columns but no dice so far.Â
View 3 Replies
View Related
Jun 18, 2007
i have created table all fields of that table are null i have not assigned primary key , i want to assign primary key for that field should not null, so i want to assign not null to field how to do
View 2 Replies
View Related
Dec 20, 2003
Maybe I'm doing something weird... but here's the problem I'm having.
I made a small ASP.NET (C#) site on my local machine that connects to SQL 2000. When I test the application it runs great. Everything gets stored into the database and the tables that it is suppose to.
I upload the site to a hosting company and when I run it, I get all sorts of error with the database. (I also copied the database from my local machine to the server via Enterprise Manager.)
For example, when I run the registration page - I get the error message:
"Cannot insert the value NULL into column 'user_id', table 'xxx.xxxx.tbl_users'; column does not allow nulls. INSERT fails. The statement has been terminated. "
I checked the table properties and my columns are set to allow null values. With the exception of having a primary key set to a column for indentity purpose (user_id).
The weird part is that I checked to see if the data are being stored into the column... and it is! Everything that was sent from the form is being stored into the table.
So I don't understand the problem I am having. Can anyone shed some light for me?
Below is the function I've written that inserts the data into the table.
===========================
C# Function to insert data
===========================
// Store Data to String
string strFirst = reg_fname.Text.ToString().Trim();
string strLast = reg_lname.Text.ToString().Trim();
string strEmail = reg_email.Text.ToString().Trim();
string strZip = reg_zip.Text.ToString().Trim();
string strCountry = reg_country.Text.ToString().Trim();
// Open Connection to Database
string strConnection = ConfigurationSettings.AppSettings["xxxxx"];
string strSQL = "INSERT INTO tbl_registration (first_name, last_name, email, zip, country) VALUES ('"+ strFirst.Replace("'", "") +"', '"+ strLast.Replace("'", "") +"', '"+ strEmail.Replace("'", "") +"', '"+ strPassword.Replace("'", "") +"', '"+ strZip.Replace("'", "") +"', '"+ strCountry.Replace("'", "") +"')";
// Execute Connection and INSERT Data
SqlConnection oConnection = new SqlConnection(strConnection);
oConnection.Open();
SqlCommand oCommand = new SqlCommand(strSQL, oConnection )oCommand.ExecuteNonQuery();
oConnection.Close();
View 2 Replies
View Related
Feb 21, 2008
I have below query inside stored procedure
select groupno,a from table1
where groupno <> 'Test'
It is not returning rows where groupno is null. I did recompile sp with SET ANSI_NULLS off. But it is not working. Any suggestions? Please help
Thank you
View 8 Replies
View Related
Sep 9, 1998
I want to modify this column:
codkey int NULL
to:
codkey int NOT NULL
How can I do that in SQL Server?
I think it must be very simple
View 2 Replies
View Related
Jun 5, 2007
Hi.I've read up on this, and have something that works, but I was wondering ifthere is anything I'm overlooking with this.Situation is:I have a bunch of tables.. I need to modify table2 as part of an upgrade of adatabase schema.I am using T-SQL scripts to do the trick which I'm writing myself.I need to add a new varchar(8) column that is not null to the primary key.I have a default I would like to use for the initial ddl modification.I want to get rid of the default after the modification is complete, but leavethe column not null for future operations...(Some if the code I'm using I took from one of Erlands posts.. hope I'm notabusing it).Here is the code I'm using now.. it basically adds the column 'institution_id'as not null along with a default.Then I jump through a couple of hoops trying to get rid of the default.Finally I setup the primary key again.I can only feel I'm supposed to be maybe using a constraint column with a nameto do this easier/more properly.set @dynamicsql = ' alter table institution_xref add institution_idvarchar(60) not null default ''' + @default_institution_id + ''' 'EXEC (@dynamicsql)set @dynamicsql = ' alter table institution_xref alter columninstitution_id varchar(60) not null 'EXEC (@dynamicsql)select @institution_iddefault = object_name(cdefault) from syscolumnswhere id = object_id('institution_xref') and name = 'institution_id'exec(' alter table institution_xref drop constraint ' +@institution_iddefault)set @dynamicsql = ' alter table institution_xref drop constraintinstitution_xref_pk 'EXEC (@dynamicsql)set @dynamicsql = ' alter table institution_xref with nocheck addconstraint institution_xref_pk primary key clustered (originalcode,institution_id) 'EXEC (@dynamicsql)thanksJeffJeff Kish
View 2 Replies
View Related
Dec 13, 2007
Hi,
I have a question whether set the default of column to null or non-null value as it is not easy to make a WHERE clause if the column is nullable.
Any suggestion?
View 6 Replies
View Related
Mar 16, 2007
It is issues like this that drive a programmer insane! I am trying to figure out if I am missing something here.
I have a query like this:
SELECT CL.DivisionId FROM CompanyLabels CL, BusinessRules B WHERE CL.CompanyLabelId = B.CompanyLabelId
In my table, DivisionId is nullable and equal to NULL.
In my VS.2005 Mobile 5 application, this line is giving me fits:
if (dr["DivisionId"] != null) { MessageBox.Show(dr["DivisionId"].ToString().Length.ToString()); divisionId = Convert.ToInt32(dr["DivisionId"].ToString()); }
DivisionId passes the null check and is blank. The message box returns "0" and of course, I get a FormatError on the conversion.
I have also tried DBNull in place of null. Is there a special System.Data.SqlServerCe NULL value in the SQL CE framework that I should be using? Am I completely forgetting something here?
Thanks!
Michael
View 3 Replies
View Related
Sep 20, 2006
Hey. I need to substitute a value from a table if the input var is null. This is fine if the value coming from table is not null. But, it the table value is also null, it doesn't work. The problem I'm getting is in the isnull line which is in Dark green color because @inFileVersion is set to null explicitly and when the isnull function evaluates, value returned from DR.FileVersion is also null which is correct. I want the null=null to return true which is why i set ansi_nulls off. But it doesn't return anything. And the select statement should return something but in my case it returns null. If I comment the isnull statements in the where clause, everything works fine. Please tell me what am I doing wrong. Is it possible to do this without setting the ansi_nulls to off??? Thank you
set ansi_nulls off
go
declare
@inFileName VARCHAR (100),
@inFileSize INT,
@Id int,
@inlanguageid INT,
@inFileVersion VARCHAR (100),
@ExeState int
set @inFileName = 'A0006337.EXE'
set @inFileSize = 28796
set @Id= 1
set @inlanguageid =null
set @inFileVersion =NULL
set @ExeState =0
select Dr.StateID from table1 dR
where
DR.[FileName] = @inFileName
AND DR.FileSize =@inFileSize
AND DR.FileVersion = isnull(@inFileVersion,DR.FileVersion)
AND DR.languageid = isnull(@inlanguageid,null)
AND DR.[ID]= @ID
)
go
set ansi_nulls on
View 3 Replies
View Related
Apr 19, 2006
HI,ALL:
I'm new to store procedure in sql 2000,now I create a sp to generate Balance report data ,
but when I run my sp in sql 2000 Query analyzer,I can get the data and some of data is null.
Now I want to replace null with '0' in my sp result data, is it possible to do it in store procedure in design model. ?
how to get the soluation ?
thanks a lot!
View 1 Replies
View Related
May 19, 2006
Hello,
I have a SQL database and it was converted from Pervasive. During the database conversion, by mistake it was transfered the NULLs in numeric fileds. Do anybody have any ideea how can we corect this? I'm thinking if is any way to check for corrupted data.
Thank you in advance for any help,
Diana
View 7 Replies
View Related
May 7, 2007
I am trying to create a drop down list with the possible usernames that you can send an email to.  Everything works fine except for the dropdown list and I get the following error message:Cannot insert the value NULL into column 'EmailTo', table 'db191165913.dbo191165913.Email'; column does not allow nulls. INSERT fails.The statement has been terminatedMy code is below:<%@ Page Language="VB" MasterPageFile="~/real_world/realworld_MasterPage.master" AutoEventWireup="false" CodeFile="send_messages.aspx.vb" Inherits="send_messages" title="Untitled Page" %><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <asp:Label ID="email_label" runat="server" Visible="False"></asp:Label> <asp:SqlDataSource ID="emailsend_source" runat="server" ConnectionString="<%$ ConnectionStrings:IMS_DB %>" DeleteCommand="DELETE FROM WHERE [EmailID] = @EmailID" InsertCommand="INSERT INTO ([UserID], [EmailTo], [EmailFrom], [Subject], [Message], [Status], [Reply], [Forward], [UserName], [SentOn], [IP], [BrowserInfo], [DNSInfo]) VALUES (@UserID, @EmailTo, @EmailFrom, @Subject, @Message, '@Status', '@Reply', '@Forward', @UserName, @SentOn, @IP, @BrowserInfo, @DNSInfo)" SelectCommand="SELECT * FROM WHERE ([UserID] = @UserID)" UpdateCommand="UPDATE SET [UserID] = @UserID, [EmailTo] = @EmailTo, [EmailFrom] = @EmailFrom, [Subject] = @Subject, [Message] = @Message, [Status] = @Status, [Reply] = @Reply, [Forward] = @Forward, [UserName] = @UserName, [BrowserInfo] = @BrowserInfo, [DNSInfo] = @DNSInfo WHERE [EmailID] = @EmailID"> <DeleteParameters> <asp:Parameter Name="EmailID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="UserID" /> <asp:Parameter Name="EmailTo" Type="String" /> <asp:Parameter Name="EmailFrom" Type="String" /> <asp:Parameter Name="Subject" Type="String" /> <asp:Parameter Name="Message" Type="String" /> <asp:Parameter Name="Status" Type="String" /> <asp:Parameter Name="Reply" Type="String" /> <asp:Parameter Name="Forward" Type="String" /> <asp:Parameter Name="UserName" Type="String" /> <asp:Parameter Name="BrowserInfo" Type="String" /> </UpdateParameters> <SelectParameters> <asp:ControlParameter ControlID="email_label" Name="UserID" PropertyName="Text" /> </SelectParameters> <InsertParameters> <asp:Parameter Name="UserID" /> <asp:Parameter Name="EmailTo" Type="String" /> <asp:Parameter Name="EmailFrom" Type="String" /> <asp:Parameter Name="Subject" Type="String" /> <asp:Parameter Name="Message" Type="String" /> <asp:Parameter Name="Status" Type="String" /> <asp:Parameter Name="Reply" Type="String" /> <asp:Parameter Name="Forward" Type="String" /> <asp:Parameter Name="UserName" Type="String" /> <asp:Parameter Name="IP" Type="String" /> <asp:Parameter Name="SentOn" Type="datetime" /> <asp:Parameter Name="BrowserInfo" Type="String" /> <asp:Parameter Name="DNSInfo" Type="String" /> </InsertParameters> </asp:SqlDataSource> <asp:SqlDataSource ID="username_email" runat="server" ConnectionString="<%$ ConnectionStrings:IMS_DB %>" SelectCommand="SELECT [UserName] FROM [Membership] ORDER BY [UserName]"> </asp:SqlDataSource> <asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="You must fill out the following forms:" ValidationGroup="email_send" /> <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="EmailID" DataSourceID="emailsend_source" DefaultMode="Insert" GridLines="None" Height="50px" Width="125px"> <Fields> <asp:BoundField DataField="EmailID" HeaderText="EmailID" InsertVisible="False" ReadOnly="True" SortExpression="EmailID" /> <asp:TemplateField HeaderText="To" SortExpression="EmailTo"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("EmailTo") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="emailsend_source" DataTextField="UserName" SelectedValue='<%# Bind("UserName") %>' AppendDataBoundItems="True" DataValueField="UserName"> <asp:ListItem>-- Receiving User --</asp:ListItem> </asp:DropDownList> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DropDownList1" Display="Dynamic" ErrorMessage="Message Receiver (To)" ValidationGroup="email_send"></asp:RequiredFieldValidator> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("EmailTo") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="From" SortExpression="EmailFrom"> <EditItemTemplate> <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("EmailFrom") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:LoginName ID="login_name" runat="server" /> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("EmailFrom") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Subject" SortExpression="Subject"> <EditItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Subject") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="TextBox3" runat="server" MaxLength="50" Text='<%# Bind("Subject") %>' ValidationGroup="send_email"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox3" Display="Dynamic" ErrorMessage="Subject" ValidationGroup="email_send"></asp:RequiredFieldValidator> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label3" runat="server" Text='<%# Bind("Subject") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Message" SortExpression="Message"> <EditItemTemplate> <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Message") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="TextBox4" runat="server" Columns="40" MaxLength="500" Rows="10" Text='<%# Bind("Message") %>' TextMode="MultiLine" ValidationGroup="send_mail"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox4" Display="Dynamic" ErrorMessage="Message" ValidationGroup="email_send"></asp:RequiredFieldValidator> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label4" runat="server" Text='<%# Bind("Message") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:CommandField InsertText="Send Message" ShowInsertButton="True" ValidationGroup="email_send" /> </Fields> </asp:DetailsView></asp:Content>
View 2 Replies
View Related