WITH RETURNS NULL ON NULL INPUT Not Working?

May 3, 2006

Hello.

I've built a sample CLR function with the following declaration....

CREATE FUNCTION GetManager(@DeptCode nvarchar(3))
RETURNS nvarchar(1000)
WITH RETURNS NULL ON NULL INPUT
AS
EXTERNAL NAME Assembly1.[ClassLibrary1.MyVBClass].MyManager

And it works as expected, except when I use NULL:

DECLARE @MyManager nvarchar(1000)
EXEC @MyManager = dbo.GetManager NULL
PRINT @MyManager

It returns the value "Unknown" as it would have for any unknown DeptCode, as-programmed.

I'm of the theory it should have returned NULL without actually firing the function? Or is this only for non-CLR items... or stored procedures, not functions?

View 3 Replies


ADVERTISEMENT

Problem With Isnull. Need To Substitute Null If A Var Is Null And Compare It To Null And Return True

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

Returns A NULL Value

Oct 9, 2014

I havethe following query which returns one row of data, however, the MedicalcodeID is NULL.

SELECT db1.dbo.Referral.ReferralGuidDigest, dbo.patient.PatientID, dbo.Consultation.ConsultationID, dbo.Staff.StaffID,
db1.dbo.Referral.EffectiveDateTime AS EventDate, db1.dbo.Referral.Status AS ReferralStatus, db1.dbo.Referral.Mode AS ReferralMode,
db1.dbo.Referral.ServiceType, db1.dbo.Referral.Urgency, db1.dbo.Referral.Direction, db1.dbo.Referral.Transport,
db1.dbo.Referral.EndedDate, db1.dbo.Referral.ReceivedDate, dbo.lkupMedical.MedicalCodeID, db1.dbo.Referral.Term,

[code]...

It is clear from teh above - that the expected MedicalCodeID = 33959 and NOT NULL. I dont understand why SQL added the COLLATE SQL_Latin1_General_CP1_CS_AS to the query - am working on a database developed by another person. Could it be the ACode and ReadCode in dbo.lkupMedical is not set up with SQL_Latin1_General_CP1_CS_AS. How to implement to LkupMedical table....

I changed HIGHLIGHTED JOIN to Inner/Right but it never yielded any results, no record found..

View 12 Replies View Related

Select Sum() Returns Null

Jan 21, 2004

hi,

i have the following query to sum the total due balance for a customer:

select sum(outstanding)from out where customer = 'myvariable' the problem is when the customer has no outstanding it returns NULL is there a way to return 0 when there are no outstanding?

thanks

View 7 Replies View Related

@@servername Returns NULL

Jul 23, 2005

I am trying to script out the creation of database scripts. I am tryingto use @@servername in the statement. I found out the select@@servername returns NULL. I used sp_dropserver to drop any servernamesfirst, restarted SQL, ran sp_addserver 'servername' to add theservername, restarted SQL. select @@servername still returns NULL...Any ideas why this may be happening?Thanks,TGru*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!

View 2 Replies View Related

ExecuteScalar Returns Null

Oct 25, 2006

I am using the following C# code and T-SQL to get result object from aSQL Server database. When my application runs, the ExecuteScalarreturns "10/24/2006 2:00:00 PM" if inserting a duplicated record. Itreturns null for all other conditions. Does anyone know why? Doesanyone know how to get the output value? Thanks.------ C# -----aryParams = {'10/24/2006 2pm', '10/26/2006 3pm', 2821077, null};object oRtnObject = null;StoredProcCommandWrapper =myDb.GetStoredProcCommandWrapper(strStoredProcName ,aryParams);oRtnObject = myDb.ExecuteScalar(StoredProcCommandWrapper);------ T-SQL ---ALTER PROCEDURE [dbo].[procmyCalendarInsert]@pBegin datetime,@pEnd datetime,@pUserId int,@pOutput varchar(200) outputASBEGINSET NOCOUNT ON;select * from myCalendarwhere beginTime >= @pBegin and endTime <= @pEnd and userId = @pUserIdif @@rowcount <0beginprint 'Path 1'set @pOutput = 'Duplicated reservation'select @pOutput as 'Result'return -1endelsebeginprint 'Path 2'-- check if upperlimit (2) is reachedselect rtrim(cast(beginTime as varchar(30))) + ', ' +rtrim(cast(endTime as varchar(30))),count(rtrim(cast(beginTime as varchar(30))) + ', ' +rtrim(cast(endTime as varchar(30))))from myCalendargroup by rtrim(cast(beginTime as varchar(30))) + ', ' +rtrim(cast(endTime as varchar(30)))having count(rtrim(cast(beginTime as varchar(30))) + ', ' +rtrim(cast(endTime as varchar(30)))) =2and (rtrim(cast(beginTime as varchar(30))) + ', ' +rtrim(cast(endTime as varchar(30))) =rtrim(cast(@pBegin as varchar(20)))+ ', ' + rtrim(cast(@pEnd asvarchar(20))))-- If the @@rowcount is not equal to 0 then-- at the time between @pBegin and @pEnd the maximum count of 2 isreachedif @@rowcount <0beginprint 'Path 3'set @pOutput = '2 reservations are already taken for the hours'select @pOutput as 'Result'return -1endelsebeginprint 'Path 4'--safe to insertinsert dbo.myCalendar(beginTime, endTime,userId)values (@pBegin, @pEnd, @pUserId)if @@error = 0beginprint 'Path 4:1 @@error=' + cast(@@error as varchar(1))print 'Path 4:1 @@rowcount=' + cast(@@rowcount as varchar(1))set @pOutput = 'Reservation succeeded'select @pOutput as 'Result'return 0endelsebeginprint 'Path 4:2 @@rowcount=' + cast(@@rowcount as varchar(1))set @pOutput = 'Failed to make reservation'select @pOutput as 'Result'return -1endendendEND

View 1 Replies View Related

AcquireConnection Returns Null Value

Mar 18, 2007

I have the following code in my custom source component's AcquireConnection method -

if (ComponentMetaData.RuntimeConnectionCollection[0].ConnectionManager != null)

{

ConnectionManager cm = Microsoft.SqlServer.Dts.Runtime.DtsConvert.ToConnectionManager(ComponentMetaData.RuntimeConnectionCollection[0].ConnectionManager);

ConnectionManagerAdoNet cmado = cm.InnerObject as ConnectionManagerAdoNet;

if (cmado == null)

throw new Exception("The ConnectionManager " + cm.Name + " is not an ADO.NET connection.");

// Get the underlying connection object.
this.oledbConnection = cmado.AcquireConnection(transaction) as OleDbConnection;

if (oledbConnection == null)

throw new Exception("The ConnectionManager is not an ADO.NET connection.");

isConnected = true;

}

The value of oledbConnection is null.

I am trying to invoke the above method within a package that I am trying to create dynamically. Any help ?

private const string ADONETConnectionString = "Provider=SQLOLEDB.1;Data Source={0};Initial Catalog={1};Integrated Security=True;";

ConnectionManager PubTRCM = package.Connections.Add("ADO.NET:OLEDB");

PubTRCM.Name = "PubTR";

PubTRCM.ConnectionString = String.Format(ADONETConnectionString, paramPubServer, paramPubTRDB);

#region Create OLEDB Source Component

//Create a OLEDB Source Component
IDTSComponentMetaData90 Source = dataFlow.ComponentMetaDataCollection.New();
Source.Name = "OLEDBSource";

Source.ComponentClassID = typeof(Microsoft.Samples.SqlServer.Dts.AdoSourceSample).AssemblyQualifiedName;

//Get the design time instance of the source
CManagedComponentWrapper SourceDesignTime = Source.Instantiate();

//Initialize the component
SourceDesignTime.ProvideComponentProperties();

if (Source.RuntimeConnectionCollection.Count > 0)
{
Source.RuntimeConnectionCollection[0].ConnectionManagerID = PubTRCM.ID;
Source.RuntimeConnectionCollection[0].ConnectionManager = DtsConvert.ToConnectionManager90(PubTRCM);
}

SourceDesignTime.SetComponentProperty("SqlStatement", "Select PlantId from PlantDim");

//Reinitialize the metadata
SourceDesignTime.AcquireConnections(null);
SourceDesignTime.ReinitializeMetaData();
SourceDesignTime.ReleaseConnections();

#endregion

View 3 Replies View Related

AcquireConnection Returns Null

May 15, 2006

Hi,

we are facing some issue to get the underlying OledbConnection from the runtime ConnectionManager.

below is the code sample that we are using

IDtsConnectionService conService = (IDtsConnectionService)this.serviceProvider.GetService(typeof(IDtsConnectionService));

if (conService == null)

return;

ArrayList conCollection = conService.GetConnectionsOfType("OLEDB");

for (int count = 0; count < conCollection.Count; count++)

{

string conName = ((ConnectionManager)conCollection[count]).Name;

if (conName == conMgrname)

{

conMgr = DtsConvert.ToConnectionManager90((ConnectionManager)conCollection[count]);

ConnectionManager cm = DtsConvert.ToConnectionManager(conMgr);

Microsoft.SqlServer.Dts.Runtime.Wrapper.ConnectionManagerAdoNet cmado = cm.InnerObject as Microsoft.SqlServer.Dts.Runtime.Wrapper.ConnectionManagerAdoNet;

OleDbConnection conn= cmado.AcquireConnection(null) as OleDbConnection;

}

}

In the sample above the conn is null.



To this query Darren replied to use the connection of type ADO.NET:System.Data.OleDb.OleDbConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 to create the connection.

Your call to GetConnectionsOfType("OLEDB"); will return native OLE-DB connections, not ADO.NET connections, using the OleDbConnection.

The connection type for the ADo>NET OLE-DB connection is -

ADO.NET:System.Data.OleDb.OleDbConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089


but if user creates an New OLEDB Connection from the Connection Manager panel of the BIDS and selects the same from the custom UI how to get the underlying OLEDBConnection? the CreationName in this case is "OLEDB" and not ADO.NET:System.Data.OleDb.OleDbConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.

View 7 Replies View Related

Decrypting Returns A NULL Value

Apr 26, 2007













I find it weird when decrypting a column from a baked up database and restoring it to another database. Here's the scenario:

Server1 has Database1.
Database1 has Table1 with two columns encyrpted -- Card Number and SS Number
Encryption and decryption in this Database1 is perfectly fine. Records are encrypted and can be decrypted too.
Now, I tried to backup this Database1 and restore it to another server with SQL 2005 instance called Server2. Of course the columns Card and SS Numbers were encrypted. I tried decrypting the columns using the same command to decrypt in Database1, however, it returns a NULL value


Here's exactly what I did to create the encyprtion and decryption keys on the restored database:
-- Create the master key encryption
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'myMasterPassword'

-- Create a symetric key
CREATE SYMMETRIC KEY myKey WITH ALGORITHM = DES
ENCRYPTION BY Password='myPassword';
Go

-- Create Card Certificate
CREATE CERTIFICATE myCert WITH SUBJECT = 'My Certificate on this Server';
GO

-- Change symmetric key
OPEN SYMMETRIC KEY myKey DECRYPTION BY PASSWORD = 'myPassword';

-- I then verified if the key is opened
SELECT * FROM sys.openkeys




If I create a new database, say Database2 from that Server2, create table, master key, certificate, and symmetric key. Encrpytion and decryption on Database2 will work!




Any suggestions gurus? I tried all searches and help for almost 2 weeks regarding this issue but nobody could resolve this.

Thanks in advance!



faiga16



3 Posts

View 9 Replies View Related

@@servername Returns NULL Value

Mar 9, 2006

I have a SQL 2005 clustered server which is returning a Null value for @@servername. I find the server entry in sysservers. I have replication configured on this so i am not able to do a Sp_dropserver & sp_addserver as this acts as a publisher. The configured merge repication stopped working because of this issue and I am not able to delete replication as the the delete option uses @@servername which returns a null value. So I am struck in a loop.

Any advice is appreciated.



thanks

View 2 Replies View Related

Concatenated Column Returns Null

Mar 7, 2008

Hi folks,I have an issue with a column I created in my query called Instance.SELECT Object_Id, Event_type, Audience, Subject, Provider, Academic_Year, Start_date, End_date, CONVERT(varchar, Academic_Year) + ' (' + CONVERT(varchar, Start_date, 103) + ') : ' + Event_type AS InstanceFROM EventsORDER BY Event_type Above is my query. The problem is because the start date column can be null, it also returns the Instance column as null for that row.I thought it would have just missed out the date and display the rest, but it doesn't.Is there any way I could get the Instance column to display a value, when the start date is null?ThanksEdit: Managed to sort it using ISNULL()

View 14 Replies View Related

Scheduledefinition.Item Returns Always Null

Jan 4, 2007

Hi All,

I have a built an application to manage the report-subscription on my ReportServer.
I'm having some troubles with retrieving the subscription properties.


My problem:
I can retrieve all my propertie except the schedule definition, when I deserialize it, the Sceduledefenition.Item always returns null.

I use the next code to deserialize it:
//////////////////////////////////////////////////////////////////////////////////////////////////////
private XmlAttributeOverrides GetSchedule()
{
XmlAttributeOverrides xmlAttrOverride = new XmlAttributeOverrides();
XmlAttributes XmlAttr = new XmlAttributes();
XmlAttr.Xmlns = false;
xmlAttrOverride.Add(typeof(ScheduleDefinition), XmlAttr);
xmlAttrOverride.Add(typeof(MinuteRecurrence), XmlAttr);
xmlAttrOverride.Add(typeof(DailyRecurrence), XmlAttr);
xmlAttrOverride.Add(typeof(WeeklyRecurrence), XmlAttr);
xmlAttrOverride.Add(typeof(MonthlyRecurrence), XmlAttr);
xmlAttrOverride.Add(typeof(MonthlyDOWRecurrence), XmlAttr);
xmlAttrOverride.Add(typeof(DaysOfWeekSelector), XmlAttr);
xmlAttrOverride.Add(typeof(MonthsOfYearSelector), XmlAttr);
return xmlAttrOverride;
}

private ScheduleDefinition DeserializeScheduleDefenition(string MatchData)
{
XmlAttributeOverrides xmlAttrOverride = GetSchedule();
XmlSerializer ser = new XmlSerializer(typeof(ScheduleDefinition),xmlAttrOverride);
Stream stream = new MemoryStream(System.Text.Encoding.Default.GetBytes(MatchData));
stream.Position = 0;
return (ScheduleDefinition)ser.Deserialize(stream);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

I'have tried almost everything, but could not find the solution.

Please, this is very important for me, so every tip or shared thought could be very helpfull.



Thnx in advance

View 2 Replies View Related

Computed Column Returns Null

Nov 16, 2007

How do you prevent SQL from returning a null value for a computed column?

The following formula returns blank if any of the values are blank ... pftitle allows nulls, the other two are required on Insert.

(((([pflastname]+', ')+[pffirstname])+' - ')+[pftitle])

Where can I find the documentation of computed field operators and expressions?

View 3 Replies View Related

ISNULL With Logical AND Returns Null

Oct 22, 2006

Im having some unexpected results from combining ISNULL with logical and '&&' and conditions '?:' in derived columns.

This works and returns A or B.
(ISNULL(Col1) && Col2 == "X") ? "A" : "B"

This fails returning Null when Col1 is null
(Col2 == "X" && ISNULL(Col1)) ? "A" : "B"

This fails returning null when Col1 is null
(ISNULL(Col1) && Col2 == "X") ? "A" : (ISNULL(Col1) && Col2 == "Y") ? "B" : "C"

I've applied service pack one and still have the issue. I've also tried using ISNULL in a condion like (ISNULL(Col1) ? TRUE : FALSE)

Anyone else seen this behavior?

View 6 Replies View Related

Default Value For NULL Value Input

Dec 5, 2007

hi,

I am using sql as a back-end server. My application requires to insert a default string values when the user do not provide any input or if the inpur is NULL. I have used the following code, but the defaul values are not inserted. I am not getting the desired result.



CREATE TABLE Employees1 (

EmployeeName varchar(50),

State char(3) NOT NULL DEFAULT 'NSW' ,

PostalCode int default 2000,

Country varchar(32) NOT NULL default 'Australia');


insert into Employees1 values ('diana', ' ' , 2,' ' )

The output is: EmployeeName State PostalCode Country


diana 2


Can anyone tell me what is that i am missing?

regards
Nongban

View 7 Replies View Related

Parameterized Query Returns One Row With Null Values.

Jul 28, 2006

I am hoping someone could help me understand why this is happening and perhaps a solution.
I am using ASP.NET 2.0 with a SQL 2005 database.
In code behind, I am performing a query using a parameter as below:
sql = "SELECT field_name FROM myTable WHERE (field_name = @P1)"
objCommand.Parameters.Add(New SqlParameter("@P1", TextBox1.Text))
The parameter is obtained from TextBox1 which has valid input. However, the value is not in the table. The query should not return ANY results. However, I am getting one single row back with null values for each field requested in the query.
The SQL user account for this query has select, insert, and update permissions on the table. The query is simple, no joins, and the table has no null values in any fields. If I perform the exact same query using an account with select only permission on the table, I get what I was expecting, no records. Then if I go back to the previous user account with more permissioins, and I change the query to pass the paramter this way:
sql = String.Format("SELECT field_name FROM myTable WHERE (field_name = {0})", TextBox1.Text)
I also get NO records retuned using the same criteria.
What is going on here? I would prefer to use the parameterized query method with the account having elevated permissions. Is there some command object setting that can prevent the null row from returning?
Thanks!

View 7 Replies View Related

DataReader Returns Different Results When There Are Null Fields

Mar 10, 2004

If I query sql server I get 10 results. But when I use if (myReader.Read()) I get only 7 results. I found that there was a Null field in the DB. I changed it and it worked.
The problem is I don't want to touch the database and set all null fields. There must be a way to get all results including the Null using sqlDataReader so that if (myReader.Read()) is used it does the right comparison.


// This code is called 10 times with a select * from where item="xxx"
P21Conn.Open();

SqlDataReader myReader = cmd.ExecuteReader();

if (myReader.Read()) {

thanks
Rod

View 2 Replies View Related

ExecuteScalar Returns 0 (null) But INSERT Is Successful.

Sep 25, 2007



I have code that has worked just fine for some time, and now all of the sudden I am having an issue. I have a simple INSERT statement built and then make the following call:


RecordID = cmd.ExecuteScalar


I have never had a problem with this before. The RecordID of the newly inserted record is returned into the RecordID Integer varibale. All of the sudden, the varibale has a value of 0 (null I assume is being returned), but yet the INSERT worked just fine. I can check the table in SQL and it is populated with no issues.

No exception is thrown of any type or anything. Does anybody know what may be happening?

View 7 Replies View Related

EncryptByKey DecryptByKey Occasionally Returns Null

Jan 21, 2008

The DecryptByKey function occasionally returns null even though the EncryptByKey function retuned a non-null value. The problem only occurs for a subset of rows returned by a single select and every time the script is executed, a different set of rows is affected by the problem. Occasionally all fields get encrypted/decrypted successfully, but this is rare.

It seems that the EncryptByKey function occasionally returns a value that can not be decrypted at a later point in time.

I am running on Windows XP Professional SP 2 with SQL Server 9.0.3042.

I have included a sample of the code below.

Thank you,
Mike

CREATE FUNCTION [dbo].[encrypt_text]
(
@input_text varchar(255)
)
RETURNS varbinary(8000)
AS
BEGIN
RETURN EncryptByKey(Key_GUID('eia_key'), @input_text)
END



CREATE FUNCTION decrypt_text
(
@input_text varbinary(8000)
)
RETURNS varchar(255)
AS
BEGIN
return convert(varchar(255),DecryptByKey(@input_text))

END



IF EXISTS (SELECT * FROM sys.symmetric_keys WHERE name = N'eia_key')

DROP SYMMETRIC KEY eia_key


CREATE SYMMETRIC KEY eia_key

WITH ALGORITHM = DES

ENCRYPTION BY PASSWORD = '???'


OPEN SYMMETRIC KEY eia_key DECRYPTION BY PASSWORD = '???'


execute util_print 'Deleting data'

execute ld_delete_lips_data

execute util_print 'Loading data'



set nocount on

insert into maturities (maturity_id, maturity_name, minimum_maturity, maximum_maturity)

values (1, 'TERM', 0, 0)

insert into maturities (maturity_id, maturity_name, minimum_maturity, maximum_maturity)

values (2, '0 - 2', 0, 2)

insert into maturities (maturity_id, maturity_name, minimum_maturity, maximum_maturity)

values (3, '2 - 5', 2, 5)

insert into maturities (maturity_id, maturity_name, minimum_maturity, maximum_maturity)

values (4, '5 - 10', 5, 10)

insert into maturities (maturity_id, maturity_name, minimum_maturity, maximum_maturity)

values (5, '10+', 10, null)

insert into forecast_horizons (forecast_horizon_id, forecast_horizon_name, forecast_horizon_alias)

values (1, dbo.encrypt_text('3 Month'), dbo.encrypt_text('Blended'))

insert into forecast_horizons (forecast_horizon_id, forecast_horizon_name, forecast_horizon_alias)

values (2, dbo.encrypt_text('1 Year'), dbo.encrypt_text('Fundamental'))

insert into forecast_horizons (forecast_horizon_id, forecast_horizon_name, forecast_horizon_alias)

values (3, dbo.encrypt_text('Technical'), dbo.encrypt_text('Technical'))



insert into forecast_levels (forecast_level_id, forecast_level_name)

values (1, dbo.encrypt_text('Low'))

insert into forecast_levels (forecast_level_id, forecast_level_name)

values (2, dbo.encrypt_text('Median'))

insert into forecast_levels (forecast_level_id, forecast_level_name)

values (3, dbo.encrypt_text('High'))



execute util_reseed_ident 'asset_classes', 0

execute util_execute_sql 'insert into asset_classes default values', 11

insert into sectors (sector_id, sector_name)

values (1, dbo.encrypt_text('Sovereign'))

insert into sectors (sector_id, sector_name)

values (2, dbo.encrypt_text('Inflation Linked'))

insert into sectors (sector_id, sector_name)

values (3, dbo.encrypt_text('Quasi & Foreign Government'))

insert into sectors (sector_id, sector_name)

values (4, dbo.encrypt_text('Securitized/Collateralized'))

insert into sectors (sector_id, sector_name)

values (5, dbo.encrypt_text('Corporate'))

insert into credit_ratings (credit_rating_id, credit_rating_name)

values (6, dbo.encrypt_text('AAA'))

insert into credit_ratings (credit_rating_id, credit_rating_name)

values (7, dbo.encrypt_text('AA'))

insert into credit_ratings (credit_rating_id, credit_rating_name)

values (8, dbo.encrypt_text('A'))

insert into credit_ratings (credit_rating_id, credit_rating_name)

values (9, dbo.encrypt_text('BBB'))

insert into sectors (sector_id, sector_name)

values (10, dbo.encrypt_text('High Yield'))

insert into sectors (sector_id, sector_name)

values (11, dbo.encrypt_text('Emerging Debt'))



set nocount off

insert into currencies (currency_id, currency_name, currency_code)

select CurrencyID, dbo.encrypt_text(CurrencyName), dbo.encrypt_text(CurrencyCode)

from lips_import..Currencies

View 3 Replies View Related

Set Input Parameter To Zero If Null Or Blank

Jan 8, 2015

I am passing few parameters to the sql function to do some calculations. If the input parameter is null or blank, then I want to set the input parameter to the value zero

View 1 Replies View Related

Null Value For Web Service Task Input

Jun 11, 2007

I'm attempting to use the Web Service task to call a method provided by a vendor. The inputs are all simple types so that helps a lot, but for one input it's a string array. If I enter a single string value for a given id using the array dialog, the method works fine.



However if I try to change the input to use a variable to provide the value it fails. I'm assuming that you can't create a variable to return a string array. Please let me know if this is the case or if I'm missing something obvious ;-)



In addition, is there a way to specify a null value for an input? Currently there doesn't appear to be a way to do this in SP2. I tried leaving the string empty which didn't work and I tried using a variable with expression "NULL(DT_WSTR, 1252)" but that failed too.

View 3 Replies View Related

How To Test If A Column Returns Null Or Not Using The Reader Object?

Apr 11, 2008

Is there a way to check for System.BDNull when I use the column name instead of column index? The column Photographer (in the excample below) sometimes contains the value null, and then it throws an error. Or do I have to go back to counting columns (column index of the returned data) again?                try {                    connection.Open();                    using (SqlDataReader reader = command.ExecuteReader()) {                        if (reader.Read()) {                            albumItem = new Album((int)reader["Id"]);                            if (reader["Photographer"] != null)                                albumItem.Photographer = (string)reader["Photographer"];                            albumItem.Public = (bool)reader["IsPublic"];                        }                    }                } Regards, Sigurd 

View 2 Replies View Related

DataRead Of Stored Procedure Returns Column Name Instead Of Null

Jan 6, 2006

I have a stored procedure like "select * from ThisTable"
I'm doing a dataread like:
Dim val as String = dateRead("column_from_ThisTable")
If the value in the column is not null everything works great, but if the value is null, instead of getting a value of "" which I expect, I get the column name??? In this case "column_from_ThisTable"
How do I make sure I get "" returned when the value in the column is db.null?

View 3 Replies View Related

Select Statement Returns Null In Stored Proc

Feb 22, 2006

If I run this statement in Query Analyzer, it properly returns 1for my testing table. But if I put the statement into a storedprocedure, the stored procedure returns NULL. What am I doingwrong? I suspect it may be related to how I defined the parametersfor the stored procedure. Perhaps my definition of TableName andColumnName don't match what COLUMNPROPERTY and OBJECT_ID expect toreceive, but I don't know where to look for the function declarationsfor those. Any pointers would be appreciated.Select statement:SELECT COLUMNPROPERTY(OBJECT_ID('Table1'), 'TestID', 'IsIdentity') ASIsIdentityTable definition:CREATE TABLE [dbo].[Table1] ([TestID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,[Description] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL) ON [PRIMARY]Stored Procedure definition:CREATE PROCEDURE spTest(@TableName varchar,@ColumnName varchar)AS SELECT COLUMNPROPERTY(OBJECT_ID(@TableName), @ColumnName,'IsIdentity') AS IsIdentity

View 2 Replies View Related

Xml Value Method Randomly Returns Null When Assigning To A Variable

Apr 20, 2007

I'm using SSEE 9.0.3042 and started loosing sleep over trying to figure out why the following piece of SQL



DECLARE @x xml

DECLARE @a nvarchar(400);

DECLARE @b nvarchar(400);

DECLARE @c nvarchar(400);

SET @x=N'<SuchKriterienDataSet xmlns="http://tempuri.org/SuchKriterienDataSet.xsd">

<SuchKriterien><Index>0</Index><Name>a</Name><Wert>Test1</Wert><Bedingung>0</Bedingung></SuchKriterien>

<SuchKriterien><Index>1</Index><Name>b</Name><Wert>Test2</Wert><Bedingung>0</Bedingung></SuchKriterien>

<SuchKriterien><Index>2</Index><Name>c</Name><Wert>Test3</Wert><Bedingung>0</Bedingung></SuchKriterien>

</SuchKriterienDataSet>';

WITH XMLNAMESPACES ('http://tempuri.org/SuchKriterienDataSet.xsd' AS ds)

SELECT

@a=@x.value('(/dsuchKriterienDataSet/dsuchKriterien/ds:Wert[../ds:Name = "a"])[1]','nvarchar(400)'),

@b=@x.value('(/dsuchkriterienDataSet/dsuchkriterien/ds:Wert[../ds:Name = "b"])[1]','nvarchar(400)'),

@c=@x.value('(/dsuchKriterienDataSet/dsuchKriterien/ds:Wert[../ds:Name = "c"])[1]','nvarchar(400)');

WITH XMLNAMESPACES ('http://tempuri.org/SuchKriterienDataSet.xsd' AS ds)

SELECT

@x.value('(/dsuchKriterienDataSet/dsuchKriterien/ds:Wert[../ds:Name = "a"])[1]','nvarchar(400)'),

@x.value('(/dsuchKriterienDataSet/dsuchKriterien/ds:Wert[../ds:Name = "b"])[1]','nvarchar(400)'),

@x.value('(/dsuchKriterienDataSet/dsuchKriterien/ds:Wert[../ds:Name = "c"])[1]','nvarchar(400)')

UNION ALL

SELECT @a,@b,@c



returns



Test1 Test2 Test3

Test1 NULL Test3



instead of



Test1 Test2 Test3

Test1 Test2 Test3



This is the shortest repro I could assemble. Once you increase the number of variables, a random pattern of dropped values emerges.



I could repro on fully patched Windows XP German w/ SSEE ENU and Windows Server 2003 64-bit w/ SSEE GER.



Any workaround highly appreciated.

Thx,

Henry

View 5 Replies View Related

IS NULL Returns Empty Records (using TEXT Type)

Mar 3, 2008

Hi all I am having some issues in selecting items from my database where the record is NOT NULL. I have the code below however although some fields do contain soem data in it, others are blank which I believe are empty spaces. How do I do a SELECT command which ignores empty spaces and NULLS?





Code Snippet

SELECT CustomSearch FROM OfficesTable WHERE CustomSearch IS NOT NULL
Thanks, Onam.

View 10 Replies View Related

How Do I Exclude Carriage Returns As Part Of A IS NULL Exclusion Clause...

Jan 6, 2005

Hi

I have stupid users... who doesn't?! They have entered carriage returns as a whole value in some fields, that is, the field contains nothing more than a carriage return.

I really need to treat these cases as nulls and have successfully removed whole fields of nothing but spaces by using the LTRIM(RTRIM()) construct. Unfortunately, this doesn't deal with carraige returns. Even CASTing and CONVERTing to varchar and then using LTRIM(RTRIM()) doesn't work.

Does anyone know how I can elegantly get around this problem other than my best guess below:

Best guess pseudo code:
IF count of field is greater than 1 THEN probably a full sentence so ignore ELSE SUBSTRING first character and if CHAR(10, etc) then treat as NULL.

Here's some code that reconstructs the problem:
select datalength(char(13)) CarriageReturnVisible
, datalength(ltrim(rtrim(cast(char(13) as varchar)))) [This Don't Work]


Cheers - Andy

View 4 Replies View Related

T-SQL (SS2K8) :: How To Modify Procedure For Input Is Null Or Zero

Apr 30, 2014

I am creating web application for state and dist wise map. I've the tables like

create table ind_state
(
ind_stat_id int,
ind_state_name varchar(50)
)
insert into ind_state values ('1','Pondi')

[Code] .....

My output is depends on the dist selection so made procedure

alter procedure LAT_TEST_DYNAM0
@dist_id int
as
begin
create table #temp (pincode varchar(10) ,latitude numeric(18,10),longitude numeric(18,10) ,descp varchar(5000))
if @dist_id!=0

[Code] ....

Myself doubt is when @dist_id is null or "0" how to show default value ?

Otherwise above my code is correct?

View 4 Replies View Related

How To Update A Column In Input Dataset With 'NA' If It's Null

Feb 6, 2007

Do I have to use condition split?, then union all?

if in script, I can use update from <tablename> Set column = isnull(column, 'NA'). It's so simple.

I'm also wondering can we run SQL Script against input dataset in a SSIS component?

 

 

View 6 Replies View Related

Eradicate Null Values From Stored Procedure Input

Apr 7, 2008

my stored procedure is

create procedure t1 (@a int,@b int,@c int,@d int,@e int,@f int)
as
begin
select no,name,department from emp where a = @a and b =@b orc =@c or
d = @d or e = @e or f = @f
end

my problem is while executing i may get null values as input to the stored procedure .
how to validate them ? any ideas .
are there any arrays.
if c and d are null then my condition would be
where a = @a and b =@b or e = @e or f = @f
how many loops shall i have to write.

View 4 Replies View Related

Script With If Condition For Multiple Input Parameter That Can Be NULL

Jan 23, 2008

I want to write an Query for a report that has 7 parameters. I want to allow Null for these parameters but at the same time in the Query i want to put an AND condition for all the parameters. I cannot put an OR condition.

For Example;
If i have a report with 2 parameters then the script will have 2* 2 If conditions

something like:-

if( @parameter1 is not Null and @parameter is not Null)
select A, B, C
From Table 1
Where parameter1 = @parameter1 and parameter2 = @prameter2

if( @parameter1 is not Null AND @parameter2 is Null)



select A, B, C
From Table 1
Where parameter1 = @parameter1

If( @parameter1 is Null AND @parameter2 is Not Null)
select A, B, C
From Table 1
Where parameter2 = @parameter2

If( @parameter1 is Null AND @parameter2 is Null)
select A, B, C
From Table 1


For 7 parameter there will be way too many If conditions. Is there an better approch to write a Query for such a situation?

View 11 Replies View Related

Setting Empty Text Box Input On Form To Null Parameter For Sql

Feb 19, 2007

Hi,
 I'm pretty new to ASP.NET and VB, but I'm working on a project which is essentially a staff directory. Using VS 2005, I've setup a basic grid view which connects to an object which connects via a data layer to a SQL database with Name, Surname, Email, Extension No and Department fields.
I have it working so that if a user enters a name and surname for example, it will return all records with either the name matching or surname matching input parameters. What I want to do is to set up a SQL query which is:
 SELECT * FROM records WHERE (Name LIKE @Name) AND (Surname LIKE @Surname) AND (Email LIKE @Email) AND (Dept LIKE @Dept)
so that if the user only enters the first name and surname for example as above, it ONLY returns the record which matches the first name and surname and not all records with either/or. One way I've thought of to do this is to convert the empty fields to "Nothing" so that it fullfils the search parameter for the empty fields. If someone can explain how to do this, or can suggest a better way, I'd be grateful.
Cheers,
Tom

View 3 Replies View Related

Passing NULL Value Not Working

Oct 24, 2007

I currently have a stored procedure that looks something like this  SELECT * FROM tblQuestions WHERE Title LIKE ISNULL('%'+@Name+'%', Title)I have a form that supplies this value.  This statement should make it so that if a NULL value is passed in, then it will return all the rows, if some text is specified, then it will not.  On my SQLDataSource on the page where the parameter is supplied I have set ConvertEmptyStringsToNull to True, but when I say in my code,SqlDataSource1.SelectParameters.Add("@Name", TextBox1.Text);It won't give me back any of the rows, I know that the stored procedure works fine because I can get it to work by a basic query and other testing on it, so somewhere in my form, the NULL value isn't being passed, I belive that it is passing an empty string and I don't know why.  Thank you in advance /jcarver 

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved