Set Input Parameter To Zero If Null Or Blank
Jan 8, 2015I 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 RepliesI 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 RepliesI am attempting to update a sql db using the update and parameter code in VB.net 2003 through MSDE for a web application. It updates changed data OK, but if the textbox value is deleted, the code does not update the sql db. I am new to this, and I'm sure it is something simple. Here is some sample code.
SqlConnection1.Open()
strSQLu = "UPDATE table1 " _
& "SET Field1Tag = @Field1Tag, Field2Tag = @Field2Tag " _
& "WHERE (Field1Tag = @Field1Tag) "
cmdCategoriesUpdate.CommandText = strSQLu
With cmdCategoriesUpdate
.Parameters("@Field1Tag").Value = txtFld1.Text
.Parameters("@Field2Tag").Value = txtFld2.Text
End With
cmdCategoriesUpdate.ExecuteNonQuery()
SqlConnection1.Close()
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?
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
Can anyone please help
I am trying to get a table from production to development created and populated with data in Prod. When I create a package to set the data flow on the available input columns in mappings I do not see any columns there. The source has been defined as the production table.
Thanks a bunch
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?
Does anyone know the trick when inserting an empty variable into a MSSQL table for it to show as null and not a blank or a zero?
It is a php variable.
Thanks
so far, i'd read a lot of books and search from internet, i still don't very understand the difference between of NULL and balnk value.
can anybody help to explain on it?
Hi,My question is, is there any difference between a NULL and a Blank(Unknown, Not Applicable) field in MS SQL or are they the same?Awaiting your comments,Regards
View 4 Replies View RelatedI have a stored procedure which takes an input parm and is supposed to return an output parameter named NewRetVal. I have tested the proc from Query Analyzer and it works fine, however when I run the ASP code and do a quickwatch I see that the parm is being switched to an input parm instead of the output parm I have it defined as...any ideas why this is happening? The update portion works fine, it is the Delete proc that I am having the problems... ASP Code...<asp:SqlDataSource ID="SqlDS_Form" runat="server" ConnectionString="<%$ ConnectionStrings:PTNConnectionString %>" SelectCommand="PTN_sp_getFormDD" SelectCommandType="StoredProcedure" OldValuesParameterFormatString="original_{0}" UpdateCommand="PTN_sp_Form_Update" UpdateCommandType="StoredProcedure" OnUpdated="SqlDS_Form_Updated" OnUpdating="SqlDS_Form_Updating" DeleteCommand="PTN_sp_Form_Del" DeleteCommandType="StoredProcedure" OnDeleting="SqlDS_Form_Updating" OnDeleted="SqlDS_Form_Deleted"><UpdateParameters><asp:ControlParameter ControlID="GridView1" Name="DescID" PropertyName="SelectedValue" Type="Int32" /><asp:ControlParameter ControlID="GridView1" Name="FormNum" PropertyName="SelectedValue" Type="String" /><asp:Parameter Name="original_FormNum" Type="String" /><asp:Parameter Direction="InputOutput" size="25" Name="RetVal" Type="String" /></UpdateParameters><DeleteParameters><asp:Parameter Name="original_FormNum" Type="String" /><asp:Parameter Direction="InputOutput" Size="1" Name="NewRetVal" Type="Int16" /></DeleteParameters></asp:SqlDataSource>Code Behind:protected void SqlDS_Form_Deleted(object sender, SqlDataSourceStatusEventArgs e){ if (e.Exception == null) { string strRetVal = (String)e.Command.Parameters["@NewRetVal"].Value.ToString(); ............................Stored Procedure:CREATE PROCEDURE [dbo].[PTN_sp_Form_Del] (
@original_FormNum nvarchar(20),
@NewRetVal INT OUTPUT )
AS
SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
DECLARE @stoptrans varchar(5), @AvailFound int, @AssignedFound int
Set @stoptrans = 'NO'
/* ---------------------- Search PART #1 ----------------------------------------------------- */
SET @AvailFound = ( SELECT COUNT(*) FROM dbo.AvailableNumber WHERE dbo.AvailableNumber.FormNum = @original_FormNum )
SET @AssignedFound = ( SELECT COUNT(*) FROM dbo.AssignedNumber WHERE dbo.AssignedNumber.FormNum=@original_FormNum )
IF @AvailFound > 0 OR @AssignedFound > 0 /* It is ok if no rows found on available table, continue on to Assigned table, otherwise stop the deletion.*/
-----This means the delete can't happen...........
BEGIN
IF @AssignedFound > 0 AND @AvailFound = 0
BEGIN
SET @NewRetVal = 1
END
IF @AssignedFound > 0 AND @AvailFound > 0
BEGIN
SET @NewRetVal = 2
END
IF @AssignedFound = 0 AND @AvailFound > 0
BEGIN
SET @NewRetVal = 3
END
END
ELSE
BEGIN
DELETE FROM dbo.Form
WHERE dbo.Form.FormNum=@original_FormNum
SET @NewRetVal = 0
---Successful deletion
END
GO
-------------------------------------------------------- When I go into the debug mode and do a quickwatch, the NewRetVal is showing as string input.
If a database's collation is blank under enterprise manager and NULL with SELECT DATABASEPROPERTYEX('<Database_Name>', 'Collation') does this mean it has the same collation as the server?
The reason I ask is that I restored a database with a different collation to my server and so I expected the different collation name to show up.
Its showing as blank though...
I thought databases kept their original collation even if restored to another server.
(The database was restored as a new database).
Hi, where I return the address details, in some of the fields they are blank, I need these blank fields as nulls, how do i do that ?
Thanks
Code Snippet
SELECT
a.[Account Name],
a.[Line Address 1],
a.[Line Address 2],
a.[Line Address 3],
a.[Line Address 4], b.*
FROM (
SELECT
abCUSA AS Company,
abCUSB AS Account,
0 AS DeliverTo,
abcnam AS [Account Name],
abcad1 AS [Line Address 1],
abcad2 AS [Line Address 2],
abcad3 AS [Line Address 3],
abcad4 AS [Line Address 4],
CONVERT(VARCHAR(20), abCUSA) + CAST(abCUSB AS VARCHAR(20)) AS [Customer Number]
FROM
LIVEAS400.S65C422B.WRFDTA.PARNADR
) a
Inner JOIN
(
SELECT
SLDATE as Date,
SLCUSA as [Company Number],
SLCUSB as [Customer Suffix],
SLDELN as [Deliber To Number],
SLTREF as [Trans Reference],
SLCNAM as [Deliver To Name],
CONVERT(VARCHAR(20), SLCUSA) + CAST(SLCUSB AS VARCHAR(20)) AS [Customer Number],
CONVERT(VARCHAR(20), SLCUSA) + CAST(SLCUSB AS VARCHAR(20)) + CAST(SLDELN AS VARCHAR(20)) AS [Full Deliver To Number],
-- SLTRT2 as [Trans type],
CASE WHEN SLTRT2 IN (92, 93, 94, 95, 98) THEN SLGDSV * -1 ELSE SLGDSV END as [Goods Value],
CASE WHEN SLTRT2 IN (92, 93, 94, 95, 98) THEN SLVATV * -1 ELSE SLVATV END as [VAT],
CASE WHEN SLTRT2 IN (92, 93, 94, 95, 98) THEN SLTOTV * -1 ELSE SLTOTV END as Total,
SLDESC as [Trans Description]
FROM LIVEAS400.S65C422B.WRFDTA.SQLSLDGR
) b ON a.[Customer Number] = b.[Customer Number]
How can I enter NULL manually in one of the rows in Sql Server database. Those rows does not contain any data.
View 3 Replies View Related
I have created a report with a stored proc which takes a parameter whose default value is null. Now when I run my stored proc in Enterprise Manager without any params I get 4 rows otherwise with proper parameter I get 2 rows.
Now I set the params value to allow for Null and blank values. When I run the report if I provide parameter value it works fine but if i try to run it without any param it shows an empty report while the stored proc running without params shows 4 rows.
I have earlier sucessfully created reports where stored procs had 4 params out of which 3 where defaulted to null. And so I set the allow nulls, Allow Blanks values to be true for those params in Rep services. So when I selected value for 1st param and ran the report I got the desired report. But this time I have only one param which can be null. But its not working.
Thanks in advance.
Data from as400 imports into SQL with blank fields which is the way as400 outputs records. How can you insert previous record of data null or blank field. ex:
ONETWO
a1
2
3
b1
2
3
Would want:
ONETWO
a1
a2
a3
b1
b2
b3
I have built a SSIS package that bascially updates two columns in table A...the update statement reads;
update Table A
set Colum 1 = ?,('?' is a variable)
Column 2 = ?
In my SSIS package, I would like to be notified/capture, if one or both variables are null....How do I do that ?..error log ?
The package runs fine both ways (if variables are null or not)
Thank you
In my report i have CNAME parameter , which allows null value. I checked Allow null value check box in report parameter properties.
when i preview the report , it displays checked NULL check box beside CNAME parameter . I want to give some meaningful name(i.e.ALLCustomers) to this checkbox instead of NULL.
Is it possible through SSRS designer?
Hi have a problem to solve and I hope that this is not a SSRS Bug.
I created a Reports(using SQL Server Project) which has several parameters which values are passed to a SP.
One of these parameter is an Integer and it is an optional value, so if the user fill it is used by the SP, otherwise the SP uses NULL and run anyway.
I starts to define tha parameter:
Datatype = integer
Allow blank value
Available: Non queried
Default: Null
if I want to Preview the report I have to provide an integer to the parameter's field ...
If for instance I set:
Default: Not queried = 0
In the moment I deploy and I use the ReportViewer in my window application the parameter's field is unabled!!
So I tried this solution:
Datatype = integer
Allow blank value
Allow null value
Available: Non queried
Default: Null
In the preview the checkbox: NULL is checked and I click on the View Report.
But when I deploy it,in the ReportViewer in my window application the parameter's field this checkbox is unchecked.
Do I forget something during my setting??I have to control it programmatically??
N.B. By default the user will not user this parameter so the best is that he can click directly on "View Report" without any additional "work" on the parameter!!
Thank you for any help!
i have a trigger on a table right now... when fields are inserted, theres a text field inserted and i want to check if that text field = '' (the empty string, not NULL) and if it doesn't equal that, then perform some row updates on other tables, but if it is empty, to not do anything else in the trigger... right now i have this:
Code:
IF ((SELECT Note FROM XATPoDetail WHERE ReqNbr = (SELECT ReqNbr FROM Inserted)) LIKE(''))
Note is the text field, XATPoDetail is the table where its being inserted into. I had to do the select FROM the table because it wouldn't let me select a text data type from the "Inserted" virtual table
but it tells me me "Error 279: The text, ntext, and image data types are invalid in this subquery or aggregate expression"
thanks
i have a trigger on a table right now... when fields are inserted, theres a text field inserted and i want to check if that text field = '' (the empty string, not NULL) and if it doesn't equal that, then perform some row updates on other tables, but if it is empty, to not do anything else in the trigger... right now i have this:
IF ((SELECT Note FROM XATPoDetail WHERE ReqNbr = (SELECT ReqNbr FROM Inserted)) LIKE(''))
Note is the text field, XATPoDetail is the table where its being inserted into. I had to do the select FROM the table because it wouldn't let me select a text data type from the "Inserted" virtual table
but it tells me me "Error 279: The text, ntext, and image data types are invalid in this subquery or aggregate expression"
thanks
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
I have a report that is run on a monthly basis with a default date of null. The stored procedure determines the month-end date that it should use should it be sent a null date.
The report works fine when I tell it to create a history entry; however, when I try to add a subscription it doesn't appear to like the null parameter value. Since I have told the report to have a default value of null it doesn't allow me to enter a value on the subscription page.
Now, I suppose I could remove the parameter altogether from the stored proc, but then the users would never be able to run the report for a previous time period. Can someone explain to me why default values aren't allowed to be used on subscriptions when they seem to work fine for ad hoc and scheduled reports? This is really quite frustrating as most of my reports require a date value and default to null so that the user doesn't have to enter them for the latest data.
An internal error occurred on the report server. See the error log for more details. (rsInternalError) Get Online Help
Key cannot be null. Parameter name: key
Hi:I have written a SQL statement that accepts a letter and then prints out all the records in a table starting with that letter. I was wondering if there is a way that I could change the query so that if prints out all records if a blank or empty value is passed in?Here's my query: ALTER PROCEDURE [dbo].[GetMediaListByFirstLetter] ( @firstLetter char(1))AS SELECT Media_ID, OrgName FROM Media WHERE UPPER(SUBSTRING(Media.OrgName,1,1)) = @firstLetterAny help doing this would be greatly appreciated.Roger
View 5 Replies View RelatedIn my report I want an optional parameter to filter all records with a specific field that is not blank. I tried several scenario's without result...
In the parameter I want to set a text value like "exampletext".
In the filter I want a check: if the parameter value is "exampletext", only show the records where field "abc" is not blank.
On the tab Filters from the Table properties I can set three values: Expression, Operator and Value.
Please help!
I have a visible DateTime parameter on the Report that I would like to make optional.
When I open up the report and try to run it without specifying the date I get a validation error that parameter is required. If I set default value to null - it works, but I have to check for both '' and NULL in my query:
StartDateTime >= @StartDate OR @StartDate='' OR @StartDate IS NULL
I tried setting default parameter using expression
=''
but I get an error that
'Default Value' of parameter 'StartDate' doesn't have expected time.
So the question is can I set DateTime parameters' default value to blank?
I build reports using reporting services 2005 sp2.
I have 3 parameters---> 3 multi value combo box .
However when I tick "allow blank value" within the report parameter
properties for this drop menu, report WILL NOT run without making
selection.(The xml is ok allow blank value set to true)
the reports still require you to enter a value for all parameters in the report when the report can and should be able to be run with no parameter defined.
the trick "default values for all of the params to "=String.Empty"" is not good .
I found this article but i can't find microsoft hotfix for it .
http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=125877
"Thank you for filing the bug. This issue has been fixed for the next CTP.
Posted by Microsoft on 8/11/2005 at 7:00 PM"
Am I missing something obvious here?
Looks like a very simple problem but not geeting it..
I have parameter as ALL and it has corresponding value as <BLANK>,which comes by default.
Allow Blank to true
How I can select this parameter as default value in parameter??
Please make sure that if I am taking '' then it is getting treated differently.I don;t want Value of ALL as '' or NULL
Niether I have permission to change sp
I want <BLANK> value to be selected internally
Any help will be appriciated.
-Thanks,
Digs
Hi,
In SSIS flat file import using fastload, I'm trying to import data into SQL 2005 previously created tables.
The table may contain column that are NULLable BUT there is NO DEFAULT for them.
If the incoming data from flat files contains nothing either between the delimeters, how can I have a NULL value inserted in the column instead of blank/empty string?
I didn't find an easy flag unless I'm doing something wrong. I know of at least two ways to do it the hard way:
1- set the DEFAULT(NULL) for EVERY column that needs this behaviour
2-set up some Derived Column option in the package to return NULL if the value is missing.
Both of the above are time consuming since I'm dealing with many tables. Is there a quick option to default the value to NULL WHEN there is NO data ELSE insert the data itself? So the same behavior that I have right now except that I want NULL in place of empty string/blank in the varchar(x) columns.
Thanks
Anatole
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.
Here's my stored procedure...
CREATE PROCEDURE [Get_WirelessProducts_By_Page]
@CurrentPage int,
@PageSize int,
@TotalRecords int output
AS
--Create a temp table to hold the current page of data
--Add and ID column to count the records
CREATE TABLE #TempTable
(
ID int IDENTITY PRIMARY KEY,
ProductID int,
ProductCategoryID nvarchar(50),
ProductBandwidthKB int,
ProductOverridePrice nvarchar(50),
UseWirelessOverridePrice bit,
DedicationTypeID int,
DedicationTypeName nvarchar(50)
)
--Fill the temp table with the Customers data
INSERT INTO #TempTable
(
ProductID,
ProductCategoryID,
ProductBandwidthKB,
ProductOverridePrice,
UseWirelessOverridePrice,
DedicationTypeID,
DedicationTypeName
)
SELECT
W.ProductID,
W.ProductCategoryID,
W.ProductBandwidthKB,
W.ProductOverridePrice,
W.UseWirelessOverridePrice,
W.DedicationTypeID,
D.DedicationTypeName
FROM
tblWirelessProducts W
INNER JOIN tblDedicationTypes D ON W.DedicationTypeID = D.DedicationTypeID
--Create variable to identify the first and last record that should be selected
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@CurrentPage - 1) * @PageSize
SELECT @LastRec = (@CurrentPage * @PageSize + 1)
--Select one page of data based on the record numbers above
SELECT
ProductID,
ProductCategoryID,
ProductBandwidthKB,
ProductOverridePrice,
UseWirelessOverridePrice,
DedicationTypeID
DedicationTypeName
FROM
#TempTable
WHERE
ID > @FirstRec
AND
ID < @LastRec
--Return the total number of records available as an output parameter
SELECT @TotalRecords = COUNT(*) FROM tblWirelessProducts
GO
Here is the relevant VB Code:
Dim parmReturnValue As SqlParameter
'conProducts is already open
cmdProducts = New SqlCommand("Get_WirelessProducts_By_Page", conProducts)
cmdProducts.CommandType = CommandType.StoredProcedure
cmdProducts.Parameters.Add("@CurrentPage", intCurrentPage)
cmdProducts.Parameters.Add("@PageSize", dgrdProducts.PageSize)
parmReturnValue = cmdProducts.Parameters.Add("@TotalRecords", SqlDbType.int)
parmReturnValue.Direction = ParameterDirection.Output
conProducts.Open
dgrdProducts.DataSource = cmdProducts.ExecuteReader()
If Not IsDBNull(cmdProducts.Parameters("@TotalRecords").Value) then
Response.Write(cmdProducts.Parameters("@TotalRecords").Value)
End IfThe rows are returned correctly, but the output parameter "@TotalRecords" doesn't return anything. Any ideas what I'm doing wrong? Thanks in advance for your help.
I have 5 Parameters created in my report.
1, 2 and 3 parameter are text inputs. 4th is multi-value parameter and 5th is again a text input. I need to Pass a blank parameter to my 5th parameter.
1) I tried the below Expression in the "UploadedEnt" DataSet Properties and not in the "Main" DataSet.
=IIF(Parameters!UploadedEntiParam.Value ="",Nothing,Parameters!UploadedEntParam.Value)
I have taken the actual sql query (file) and I have just placed the select statement.
DataSet Name: UploadedEntselect distinct UploadEnt
from
(
SELECT DISTINCT col1, col2...
....) Ent
Order by 1OR logic has been applied in the Tablix Properties Filters as an expression.=Fields!value1.Value like Parameters!value1Param.Value Or Fields!value2.Value like Parameters!value2Param.Value Or Fields!value3.Value like Parameters!value3Param.Value Or Fields!value4.Value = Parameters!value4Param.Value(0) Or Fields!UploadEnt.Value = Parameters!UploadedEntParam.ValueFilter: Expression = TRUE2) I tried applying NULL check box which works perfectly but I do not want to apply that here.How to Pass a Blank Parameter?
Is it possible to enable parameter of type date to be blank (not null)?
I created parameter of type date, gave it no default value, when I pressed the preview tab I got error message "The property 'DefaultValue' of report parameter 'DateParamName' doesn't have the expected type"
Thanks in advance!
Have a report that has this as the query:
SELECT SOURCE, TRANSDATE, LOCATION, DESCRIPTION, MOACTIVETIMESTAMP, MOINACTIVETIMESTAMP
FROM CTS_Missing_Data_Report_VW
WHERE LOCATION = @Location AND SOURCE = @Source AND (TRANSDATE BETWEEN @StartDate AND @EndDate)
ORDER BY Transdate desc, Location
So the user can enter a value for Location and Source and select the date range.BUT I also want the user to be able to put in nothing for the Location and Source so the query would return everything for that date range.
So if they did this the query would be
SELECT SOURCE, TRANSDATE, LOCATION, DESCRIPTION, MOACTIVETIMESTAMP, MOINACTIVETIMESTAMP
FROM CTS_Missing_Data_Report_VW
WHERE (TRANSDATE BETWEEN @StartDate AND @EndDate)
ORDER BY Transdate desc, Location
I have set the parameters @Location and @Source to "Allow blank value" in the datasets for the location and source I have :
SELECT NULL AS Source
UNION
SELECT DISTINCT RTRIM(LTRIM(SOURCE))AS Source
FROM CTS_OPS_SOURCE_LOCATION_TBL_VW
ORDER BY SOURCE
So a blank will show on the drop down and when I run the query for the Query Designer in the Dataset Properties the results does show a blank record for the first record.BUT when I Run the report there are no blanks in the drop downs for the location or source. And there is no '<blank>' selection in the drop down either. And the drop down insist the user selects a value from both of the drop downs.
What am I doing wrong?