Passing DateDiff Rather Than Actual Dates As Parameters

Nov 29, 2005

I've gotten sort of fed up with dealing with regional date settings on
the client side and am considering the following scheme - just
wondering if anyone has a negative view of it or not:

Instead of

@StartDate datetime,
@EndDate datetime

Use:

@StartDaysDiff int,
@EndDaysDiff int


In the front end app take the desired date and do a DATEDIFF with the
current date, then pass the date diff as a parameter as an integer
rather than deal with the dates at all.

Then...

DECLARE @TodayDate datetime, @StartDate datetime, @EndDate datetime

SELECT @TodayDate = GETDATE()
SELECT @StartDate = DATEDIFF(DAY,@StartDaysDiff,@TodayDate)
SELECT @EndDate = DATEDIFF(DAY,@EndDaysDiff,@TodayDate)

SELECT
a.Something
FROM
dbo.Appointments a
WHERE
a.AppointmentDate BETWEEN @StartDate and @EndDate

Just wondering ...

Thanks,
lq

View 9 Replies


ADVERTISEMENT

Dates And DATEDIFF Formula

Mar 7, 2008



I am trying to come up with a SQL statement to determine the following.

I have an OrderDetails table with items for rental. In order to determine the proper billing I have created a second table that is a foreign key to the OrderDetails table that lists the shipping and returns of each line item. the Columns in this table include a ShipActionType, Quantity and ShipActionDate. If the type is equal to 1, the action is the shipping out of an item and if the type is equal to 2, the action is the return of an item.

For example, I might have a line in OrderDetails that says Widget A, Quantity 10.

The shipping Table then might show the following in relation to this line item:

Type Qty Date
1 10 03/07/2008
2 5 03/21/2008
2 3 03/27/2008
2 2 03/29/2008

What i'd like to determine is the total number of billable days this item was out to the customer.

I have tried a variety of DateDiff formulas but have not been bale to nail it just yet.

Any suggestions? Do I need to structure my data a different way?

Any help would be appreciated.

View 36 Replies View Related

T-SQL (SS2K8) :: How Datediff Determine Difference Between Two Dates

Jan 19, 2015

select datediff(wk, '2015-01-11', '2015-01-19') returns 1 (shouldn't it return 2?)
select datediff(wk, '2015-01-10', '2015-01-19') returns 2

View 5 Replies View Related

Want To Use Parameters To Filter For Dates Between Two (parameter, User-input) Dates

Mar 2, 2006

SQL 2005 Dev

How can I do this with Parameters? I can get a single parameter to filter for a single date (or even a combo list of the dates in DB). But I want my parameters to interact so that they specify a range. Is this possible?

View 3 Replies View Related

How Can I Get Actual Operation Cost From Actual Execution Plan?

Jul 25, 2006

I have a view in SQLServer 2005. It took 30 sec. to finish. Then I deleted 4500 records from one table that is used in view. It took 90 sec. to finish now. I did a comparison on Actual Execution Plan between before I deleted data and after I deleted data, they are almost same, only different is Actual Number Rows become less after deleted data. So, I wonder why data become less but time become more. When I look closely on the Actual Execution Plan, the ridiculous thing is, there are only Estimated Operation Cost on each step, no Actual Operation Cost. I guess there are something wrong with optimizer because reuse same Execution Plan, but how can I tell which step wrong without Actual Operation Cost.

Thanks!

Henry

View 2 Replies View Related

Passing Dates To A Procedure

Mar 6, 2006

im throwing up some errors

Syntax error converting datetime from character string.

im sending 2 asp:Text fields to the procedure

in the format dd/mm/yyyy

i.e. 06/03/2006

the table im inserting it into is set to datetime

within the procedure i have tried both
@Date1 DateTime,
@Date2 DateTime

@Date1 Nvarchar(50),
@Date2 Nvarchar(50)

and it still throws up Syntax error converting datetime from character string.

now im not sure if i should pass it to the Procedure as Nvarchar then Convert it within the procedure ..

or change the table type to nvarchar and just insert into a non date format table type.

View 11 Replies View Related

Problem Passing Dates To Stored Procedure

Nov 27, 2000

I have a stored procedure where I am passing in two dates and looking for records between date one and date two.
If I run the SQL statement in the query analyzer I get results back however if I try to pass the same to a stored procedure it returns nothing.
Example:
This returns a result when run in query analyzer

Select distinct Employeename from thisTable where someDate between '11/20/00' and '11/27/00'

Stored procedure is:

CREATE PROCEDURE sp_Employee_Report

@StartDate datetime,
@EndDate datetime

AS
Select distinct Employeename from thisTable where someDate between @StartDate and @EndDate

return nothing.

The someDate field is of date type datetime.
Anyone know why this does not work in the stored procedure?
Thanks for any help

View 1 Replies View Related

Parameters Passing

Mar 14, 2008

Hi,
 how to pass paremeters in sqldataadapter? here iam checking authentication using sqlcommand and datareader
like that if iam checking authentication using dataset and sqldatareader how to use parameters?
 
SqlConnection cn = new SqlConnection("user id=sa;password=abc;database=xyz;data source=server");
cn.Open();
// string str = "select username from security where username='" + TextBox1.Text + "'and password='" + TextBox2.Text + "'";
string str = "select username from security where username=@username and password=@password";
SqlCommand cmd = new SqlCommand(str, cn);
cmd.Parameters.AddWithValue("@username", TextBox1.Text);
cmd.Parameters.AddWithValue("@password", TextBox2.Text);
SqlDataReader dr = cmd.ExecuteReader();

if (dr.HasRows)
{
Session["username"] = TextBox1.Text;
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);


}
else
{
Label1.Visible = true;
Label1.Text = "Invalid Username/Password";
}
-------------------------------------------------------------------------------------
like that if iam checking authentication using dataset and sqldatareader how to use parameters?SqlConnection cn = new SqlConnection("user id=sa;password=abc;database=xyz; data source=server");
cn.Open();ds = new DataSet();
string str = "select username from security where username=@username, password=@password";da = new SqlDataAdapter(str, cn);  //how to pass parameters for that
da.Fill(ds, "security");
Response.Redirect("dafault2.aspx");

View 2 Replies View Related

Passing Parameters To DTS In C#

Apr 17, 2004

I have a dts package file. I am able to execute the file thro C#. I want to pass userid, password, datasource through program. How to do this?

DTS.PackClass package = new DTS.PackClass();

string filename = @"c:abc.dts";
string password = null;
string packageID = null;
string versionID = null;
string name = "DTSPack";
object pVarPersistStfOfHost = null;

package.LoadFromStorageFile(filename, password, packageID,
versionID, name, ref pVarPersistStfOfHost);
package.Execute();
package.UnInitialize();
package = null;


Thanks
Jtamil

View 2 Replies View Related

HELP! Passing Parameters

May 30, 2006

Still need help passing a criteria parameter query from a SQL Function (i.e. @StartDate) to a report header in Access Data Project where header = 'Transactions As Of [StartDate].

If anyone knows anywhere I can get help on this, I would really appreciate it. Thanks.

View 1 Replies View Related

Select Parameters With Dates

Jan 16, 2007

I have a sqlDataSource control that has its select command and parameters set dynamically.  One of the parameters is a date, which should be in smalldatetime format (ie, 12/22/2006).  Obviously, using SQL Server, the data is stored with both date and time.  The problem is, I cannot get any data selected.   I initially thought that I needed to tell it to only look at the date and not the time, but from what I have seen this should work. Here is the pertinent code. 
dim seldate as datetime
selDate = Session("ChosenDate")
Dim SelCmd As String = "SELECT [PatientName], [AssignedTo], [CPT], [CPT2], [HospitalID], [RoomNbr], [ACType], [TxDx1], [TxDx2], [MRNbr], [Notes], [PatientID], [PCPID], [ResidentID], [Status], [CaseID], [AdmitDate], [crtd_datetime] FROM [DailyBilling] WHERE ([crtd_datetime] = @crtd_datetime) and ([AssignedTo] = @AssignedTo) and ([HospitalID] = @HospitalID) ORDER BY [PatientName]"
SqlDataSource1.SelectCommand = SelCmd
SqlDataSource1.SelectParameters.Clear()
 
 
Dim parFilterProvider As New ControlParameter()
parFilterProvider.ControlID = "ddlProvider"
parFilterProvider.Name = "AssignedTo"
parFilterProvider.Type = TypeCode.String
SqlDataSource1.SelectParameters.Add(parFilterProvider)
 
 
Dim parFilterHospital As New ControlParameter()
parFilterHospital.ControlID = "ddlHospitals"
parFilterHospital.Name = "HospitalID"
parFilterHospital.Type = TypeCode.String
SqlDataSource1.SelectParameters.Add(parFilterHospital)
 
 
 
Dim parFilterStatus As New Parameter()
parFilterStatus.Name = "crtd_datetime"
parFilterStatus.DefaultValue = selDate.ToShortDateString
parFilterStatus.Type = TypeCode.DateTime
SqlDataSource1.SelectParameters.Add(parFilterStatus)
 
Gridview1.databind()
Any ideas?

View 5 Replies View Related

Passing Parameters In TableAdapter

Jul 28, 2006

A little new to ASP.NET pages, and I'm trying to pass some parameters to a SQL 2000 Server using a TableAdapter, code is as follows:
------
TestTableAdapters.test_ModemsTableAdapter modemsAdapter = new TestTableAdapters.test_ModemsTableAdapter();
// Add a new modem
modemsAdapter.InsertModem(frmRDate, frmModem_ID, frmProvisioning, strDecESN );
--------
And the error I get when loading the ASP.NET page is as follows:
Compiler Error Message: CS1502: The best overloaded method match for 'TestTableAdapters.test_ModemsTableAdapter.InsertModem(System.DateTime?, string, string, string)' has some invalid arguments
---------------
Now I realized the four strings that I am trying to pass to the server refer to ID's on Textboxes on the web page. Not sure if that might be the problem for databinding... ? Or is it my statement for the adapter?
-Ed

View 4 Replies View Related

Passing Parameters Using IN Statement

Dec 7, 2006

The SQL for a dataset in ASP.NET 2.0 is as follows....
SELECT DISTINCT StudentData.StudentDataKeyFROM         Student2Roster INNER JOIN                      StudentData ON Student2Roster.StudentDataRecID = StudentData.StudentDataRecIDWHERE     (Student2Roster.ClassRosterRecID IN (@ClassRosterRecIDs)
ClassRosterRecIDs are giuds
At design time i use 'b2cf594d-908b-4c0c-a67f-6364899a4d42', '2e0b3472-d3f0-4a54-94af-bfc0a99525d9' as the parameter and it works in the designer but not at runtime.
At runtime I get the error Conversion failed when converting from a character string to uniqueidentifier.
If I leave the quotes off and only use 1 value like b2cf594d-908b-4c0c-a67f-6364899a4d42 it works.How can I use multiple guids as an IN parameter like 'b2cf594d-908b-4c0c-a67f-6364899a4d42', '2e0b3472-d3f0-4a54-94af-bfc0a99525d9'?
Thanks

View 2 Replies View Related

Passing Parameters To LIKE Function

Jul 22, 2007

 Hi,I want to pass parameter in to LIKE functionIs there anyway to do thatThanks,Janaka  

View 6 Replies View Related

Passing Dtae Parameters

Apr 10, 2008

Hi
I'm trying to add 2 date parameters to the where caluse but not sure how to structure it:
 Can anybody help?
 Public Function GetCategoryPerformance(ByVal PriorityType As String) As DataSet
'*******************************************************
'This web service will return a specific row for a table
'*******************************************************Dim cn As New SqlConnection("data source=CADTRAINING;persist security info=True;initial catalog=pathwaysreporting;user id=cad;password=cad;")
Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT * from sp_category_performance where where priority = '" & PriorityType & "'", cn)Dim ds As DataSet = New DataSet
Try
da.Fill(ds, "CategoryPerformance")Catch ex As Exception
Throw New Exception(ex.Message)
End TryReturn ds
End Function
End Class

View 2 Replies View Related

Passing Parameters To A DTS Package

Mar 10, 2005

Hello All,

I am executing a DTS package from an asp page using the following code. I would like to also pass DTS Global variables along. i assume this is possible but can't seem to find an example.


Set oPkg = Server.CreateObject("DTS.Package")
oPkg.LoadFromSQLServer "HOFDBMCRM4","TraubGar","ripley",DTSSQLStgFlag_Default,"","","","DSC_CalculateBOS"
oPkg.Execute()


Thanks, Gary

View 1 Replies View Related

Passing Parameters In ISQL

Aug 30, 2001

Hi,

I would like to pass parameters from isql command line to an input query file. I am working on SQL Server 7.0. How can I accomplish this?

My eg. is like this:

> isql.exe (all the server options etc.,) /iInputfile /oOutput file
I need the output depend on the query given in the input file with the query depending on the parameter I supply on the command line.Thanks for your help in advance.

thanks,
Sravan.

View 1 Replies View Related

Passing Parameters (Urgent)

Jul 21, 2000

I'm trying to execute this statement but due to some missing paremters its creating table in that fashion

Table created = '+@string+'_'+@string1+'

but I want table to be create as what parameters passed, can you have a look pls...

exec sp_test 'master','table'
Starts here-----------

if exists (select * from sysobjects where id
= object_id(N'[dbo].['+@string+'_'+@string1+'])
and OBJECTPROPERTY(id, N'IsUserTable') = 1)

Drop table [dbo].['+@tblName+'_'+@table1+']

CREATE TABLE [dbo].['+@string+'_'+@string1+']
(
[HESClrId] [nvarchar] (20) NULL ,
[HESClrName] [nvarchar] (60) NULL ,
[HESClrSeq] [smallint] NULL
)
ON [PRIMARY]

View 1 Replies View Related

Passing Parameters To A View

Sep 18, 2002

Can I pass a parameter to a view? Can something like this even be done?

CREATE view co_interlinks1
AS
SELECT [TDirectorships].[IDDir], [TDirectors].[DirLName] + ', ' + [TDirectors].[DirFName] AS DirectorName, [TDirectorships].[Ticker], [TCompanies].[CompanyName]
FROM TDirectorships
INNER JOIN TCompanies
ON [TCompanies].[Ticker]=[TDirectorships].[Ticker]
INNER JOIN TDirectors
ON [TDirectorships].[IDDir]=[TDirectors].[IDDir]
WHERE [TDirectorships].[IDDir] in (SELECT [TDirectorships].[IDDir]
FROM TDirectorships
WHERE Ticker=@Ticker)--This line requires a variable value corresponding to Ticker for the chosen company
and [TDirectorships].[Ticker] <> =@Ticker --This line requires a variable value corresponding to Ticker for the chosen company

View 2 Replies View Related

Getting Chart By Passing Parameters

Oct 24, 2005

Hi
I created a report based on category,time and stores as report parameters.The datasets are created by using mdx queries and the provider I selected is olap services.I would like to add a bar chart in the layout and the resultant chart should be based on the selected parameters.I am not able to get this.First of all is it possible? If so, what should I do in the chart properties?

Regards
Ranjit

View 2 Replies View Related

Passing Parameters With Xp_cmdshell

Mar 1, 1999

Is it possible to pass a parameter to an NT shell batch script when using the xp_cmdshell extended stored procedure?

View 1 Replies View Related

Passing Parameters Dynamically

Mar 20, 2008

Hi,

I have a requirement to load tables in the database from files on a shared server (lets say 50 tables from 50 files). I do not want to hardocde the file path anywhere in the package since this would mean changing 50 packages everytime the path changes (say when moving to to a diff server).

In SQL Server 2000, I used a .ini file to pass the path and used a Dynamic properties task to set run time variables. That way, evertime the path changes, I only had to change 1 ini file and all packages picked up the new path from it. How do I do this in SQL Server 2005 ?

Appreciate any assistance / suggestion in this regard.

Thanks,
Bhaskar

View 3 Replies View Related

Passing Parameters Dynamically

Mar 20, 2008

Hi,

I have a requirement to load tables in the database from files on a shared server (lets say 50 tables from 50 files). I do not want to hardocde the file path anywhere in the package since this would mean changing 50 packages everytime the path changes (say when moving to to a diff server).

In SQL Server 2000, I used a .ini file to pass the path and used a Dynamic properties task to set run time variables. That way, evertime the path changes, I only had to change 1 ini file and all packages picked up the new path from it. How do I do this in SQL Server 2005 ?

Appreciate any assistance / suggestion in this regard.

Thanks,
Bhaskar

View 8 Replies View Related

Passing Parameters To A Procedure

May 30, 2008



How does we pass dynamic number of parameters to a procedure?
Eg.

DECALRE @IDs varchar(50);

SET @IDs = '1,2,3'

SELECT Description FROM MyTable WHERE ID IN (@IDs )

Here ID is int. When I tested this, it shows an error 'Cannot covert '1,2,3' to int'. No errors while it is one number ie '1'

How I can manage this type of problem in a stored procedrue that receive the @IDs as parameters?

View 1 Replies View Related

Passing Multivalue Parameters

May 22, 2007

Hello Friends,

I have a report (Say Report 1)which is asking for a multivalue parameter Period. The user selects three period from the dropdown list available for the Parameter. Lets say that the user select 0407,0507,0607. Now is this report 1 there is a particular field which is linked to another sub report. So if the top level Report 1 supplies the revenue for 3 regions say for the periods selected then clicking on any of the regions would open a second detailed report, say Report 2 for the three periods as selected.

Till this everything is fine.

Now the problem is that in this detailed Report 2 there would be a particular text box as "Click here to naviagate back to parent report". So that when the user clicks on this cell he is taken back to the parent report, Report 1 which was originally generated for the 3 periods.

Can anyone please advise as to how the Multivalue Parameter which was passed from Report 1 to Report 2 can again be looped back to Report 1 from Report 2.



Thanx Friends,

Raktim

View 2 Replies View Related

Passing Parameters To A OLE DB Source

Mar 10, 2008

I have an OLE DB Source that talks to an Oracle Db and returns back some data. I need to be able to pass some parameters to my query from the SSIS variables.

How can accomplish this ? Do I need to create a stored proc in my Oracle DB..is that the only way I can pass parameters ?
Is so how ?

Any examples would be really appreciated

Thanks

Smx

View 13 Replies View Related

Passing Report Parameters Through URL

May 31, 2007

Hi, I've read some threads in regards to passing report parameters through the 'URL' but I am struggling to fully understand. To keep things simple I have 1 report parameter, named par_pub which brings back either ww06 or ww07. What I require is to click on a hyperlink and it directs me to my report and then populates the par_pub paramerter with ww07.

I am trying the below



http://emp6/Reports/Pages/Report.aspx?ItemPath=%2fTest+Reports%2fIT+Dev%2fSales+Summary+Detail&prefixar_pub=%WW07%



The part in bold is the location + name of the report and the later is where I am trying to pass the parameter. Can anyone please help as this is not working.

Thanks

View 10 Replies View Related

Passing UDF Parameters By Reference

Jan 14, 2008

How can we pass variables by reference to a UDF? Is there any way in SQL Server to achive this objective?

View 2 Replies View Related

Passing Parameters From One Report To Another Using URL

Nov 12, 2007



Hi,

I have a problem getting the URL string right to pass parameters from one report to another

This is the URL string I have set in the Navigation property of my text box:
"http://SQL/Reportserver$SQL2005/Pages/Report.aspx?%2fEarlyWarning2%2fratio+reports+-+test%2freport_upper_lower_benchmark_ratio1&rs:Command=Render&rcarameters=false
&company="&Parameters!company.Value.ToString()&Parameters!year.Value.ToString()&Fields!ratioName.Value.ToString()



The first thing is that when I just want to view the report say, with parameters hidden, I get this URL
http://reportserver/?%2fEarlyWarning2%2fratio+reports+-+test%2freport_upper_lower_benchmark_ratio1&rs%3aCommand=Render&rc%3aParameters=false


with the message "Internet Explorer cannot display the webpage"

Why does the first part of the URL change?

If I run it with just one parameter, company, I get the same error message with this URL :
http://reportserver/?%2fcompany.Value.ToString()&rs%3aCommand=Render&rc%3aParameters=false&company=%22

It looks like no value for the company parameter being passed

Any suggestions appreciated

Ruth

View 9 Replies View Related

Passing 2 Parameters To Report

Feb 13, 2008



Hi,
I have created a report in VS 2003 using command type as Text for a stored procedure. The stored procedure itself takes in 2 parameters.
I have passed one of them in the exec statement but the other parameter is the one which I want to pass to the stored procedure through report.
So, in short, I have got this statement in dataset

EXEC SP1 1

Which means only 1 of the arguments is being passed to the stored procedure and not the second one. I would appreciate if some one can guide me on how to pass a report parameter to the stored procedure which using command type text


Cheers.

View 5 Replies View Related

Passing Parameters To DTSPackage

Feb 6, 2008

Hai
I am havng a DTS Package name MFT_Disb... I am invoking this package from my VB.NET(2003) Application..
What i want to do is ....
1 ) i want to pass a variable named Sl_No from my Application to the DTSPackage ..
How can i pass the parameters to the package ?
2 ) Also i ve a text file named Disb.txt... i want to rename this text file to the value contained in the variable Sl_No...
For renaming the text file i want to write ActiveX Script in the same DTSPackage ... How to write the ActiveX Script ?
How can i rename the text file ?
Anybody knows plz do help me ...
I am new to SQL Server and DTSPackage
Any help appreciated
Thanx in advance

View 1 Replies View Related

Passing Parameters To DDL Statement?

Jul 12, 2007

Hi all of you,



I'd like to know how could I add parameters to CREATE TABLE from a Execute Sql Task.



Is it possible?



TIA

View 3 Replies View Related

Passing Parameters To LookUps

Jun 1, 2007

I am trying to make a SSIS package..

In the dataflow of my package, I must check from one table whether a row exists, and if that row exists, I should get some other row from another table, and update that..



I think to check whether a row exists, i should use "Look Up"



But cant we pass parameters to LookUP?



I am trying to use this SQL:



SELECT count(*) FROM ServicePackets where ID = ? and CHANGEDATE > ? and status = 1



I should get if that row exists or not only... (true or false)



How can i use parameters in LookUps?

View 7 Replies View Related







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