Hello I have and tested in 2 way using variable and constant.
Query 1: This query I am using vaiable "@last" for the date value.
this takes to run for 2 minute .
Query 2: Here I am using value '11/05/2002' instead of varialbe and it is running within a second.
Why these much difference to run this same query?.
Can anybody give correct reason or solution for this.
Thanks,
Ravi
query 1:
DECLARE @last smalldatetime
SET @last ='11/05/2002'
select distinct(o.account_num),a.enterprise_num,a.site_nu m
from oesd.dbo.order_header o WITH(NOLOCK)
INNER JOIN oesd.dbo.account a WITH(NOLOCK)
ON a.account_num = o.account_num
and o.added_date > @last
UNION
select distinct(o.account_num),a.enterprise_num,a.site_nu m
from oesd.dbo.order_header o WITH(NOLOCK)
INNER JOIN oesd.dbo.account a WITH(NOLOCK)
ON a.account_num = o.account_num
INNER JOIN Leap.dbo.ENTERPRISE_STATE es WITH(NOLOCK)
ON (a.enterprise_num = es.ENTERPRISE_NUM
AND o.last_updated_date > @last)
Query 2:
select distinct(o.account_num),a.enterprise_num,a.site_nu m
from oesd.dbo.order_header o WITH(NOLOCK)
INNER JOIN oesd.dbo.account a WITH(NOLOCK)
ON a.account_num = o.account_num
and o.added_date > '11/05/2002'
UNION
select distinct(o.account_num),a.enterprise_num,a.site_nu m
from oesd.dbo.order_header o WITH(NOLOCK)
INNER JOIN oesd.dbo.account a WITH(NOLOCK)
ON a.account_num = o.account_num
INNER JOIN Leap.dbo.ENTERPRISE_STATE es WITH(NOLOCK)
ON (a.enterprise_num = es.ENTERPRISE_NUM
AND o.last_updated_date > '11/05/2002' )
I am trying to load previous days data at 3 am via a SSIS job.
The Date variable is initiated as DATEADD("dd",-1, GETDATE()) in the for loop.
Now, as this job runs at 3 am, and I set the variable as GETDATE() - 1, it excluded the data from 12 am to 3 am in the resultset as Date is set as YYYY-MM-DD 03:00:00:000 I need this to be set as YYYY-MM-DD 00:00:00:000
DECLARE @PriorDayDate as varchar(10) DECLARE @CurrentDayDate as varchar(10) DECLARE @StartHourTime as varchar(10) DECLARE @EndHourTime as varchar(10) DECLARE @PriorDayDateANDStartHourTime as varchar(20) DECLARE @PriorDayDateANDEndHourTime as varchar(20) DECLARE @CurrentDayDateANDStartHourTime as varchar(20) DECLARE @CurrentDayDateANDEndHourTime as varchar(20)
--select @PriorDayDate --select @CurrentDayDate --select @StartHourTime --select @EndHourTime --select @PriorDayDateANDStartHourTime --select @PriorDayDateANDEndHourTime select cast(@PriorDayDateANDStartHourTime as datetime) as 'PD Start Time' select cast(@PriorDayDateANDEndHourTime as datetime) as 'PD End Time' select cast(@CurrentDayDateANDStartHourTime as datetime) as 'CD Start Time' select cast(@CurrentDayDateANDEndHourTime as datetime) as 'CD End Time'
I have a package variable that is a datetime... how am I able to set the time of that variable? In visual studio on the variables screen if I click on value it brings up a calendar control - I can't seem to edit the time portion of the variable.
When I first click open the variables window it will say 9/1/2006 12:00:00 AM - but as soon as I click on the value box the 12:00:00 AM part will disappear and I can't edit it. I've tried on someone elses PC as well to make sure there isn't something wrong with my visual studio
I'm trying to extract some data from a table in oracle. The oracle table stores date and time seperately in 2 different columns. I need to merge these two columns and import to sql server database.
I'm struggling with this for a quite a while and I'm not able to get it working.
I tried the oracle query something like this,
SELECT (TO_CHAR(ASOFDATE,'YYYYMMDD')||' '||TO_CHAR(ASOFTIME,'HH24:MM : SS')||':000') AS ASOFDATE
FROM TBLA
this gives me an output of 20070511 23:06:30:000
the space in MM : SS is intentional here, since without that space it appread as smiley
I'm trying to map this to datetime field in sql server 2005. It keeps failing with this error
The value could not be converted because of a potential loss of data
I'm struck with error for hours now. Any pointers would be helpful.
I noticed that the Reporting Services is taking longer to open in the morning or after a period of time in-active. My guest is that the SSRS is set to idle/stop after certain time when it is in-active state and it will take time to start the Reporting Services when it is activated. My question is how to make SSRS active all the time ie never go to "sleep". What is the Pro and Con of this approach? Thanks.
I'm looking for a way of taking a query which returns a set of date time fields (probable maximum of 20 rows) and looping through each value to see if it exists in a separate table.
E.g.
Query 1
Select ID, Person, ProposedEvent, DayField, TimeField from MyOptions where person = 'me'
Table
Select Person, ExistingEvent, DayField, TimeField from MyTimetable where person ='me'
Loop through Query 1 and if it finds ANY matching Dayfield AND Timefield in Query/Table 2, return the ProposedEvent (just as a message, the loop could stop there), if no match a message saying all is fine can proceed to process form blah blah.
I'm essentially wanting somebody to select a bunch of events in a form, query 1 then finds all the days and times those events happen and check that none of them exist in the MyTimetable table.
I`ve been following the newsgroups, and the consensus had seemed to be that 7.0 would be released around November. However, I spoke to a Microsoft partner last week who told me that the release date would be sometime in the second quarter of 1999. Does anyone know whether if this is true/untrue?
I was working with Microsoft Time Series model (MTS) with some data, when in the mining model viewer, decision tree tab, I realized that the key time variable that I define, it was acting like a split variable.
So, I ask you, this is possible?, because, for me, this should not happen€¦.
After, I review the Data Mining Tutorial by Seth Paul, Jamie MacLennan, Zhaohui Tang and Scott Oveson, and I found, in the Forecasting part, that the key time variable (Time Index) it was acting like a split variable too, in for example, M200 pacific:Quantity and R250 Europe:Quantity.
So people, it€™s possible that a key time variable act like a split variable in a MTS model?
I need to set a variable to datetime and time to exact milliseconds in SQL server in stored procedure.
Example: set MyUniqueNumber = 20071101190708733 ie. MyUniqueNumber contains yyyymmddhhminsecms
Please help, i tried the following: 1. SELECT CURRENT_TIMESTAMP; ////// shows up with - & : , I want single string as in above example.2. select cast(datepart(YYYY,getdate()) as varchar(4))+cast(datepart(mm,getdate()) as char(2))+convert(varchar(2),datepart(dd,getdate()),101 )+cast(datepart(hh,getdate()) as char(2))+cast(datepart(mi,getdate()) as char(2))+cast(datepart(ss,getdate()) as char(2))+cast(datepart(ms,getdate()) as char(4))
This one doesnot display day correctly, it should show 01 but shows 1
I have an SSIS package that moves data from SQL Server to an legacy Access database. In SQL Server, there is a date/time column that I need to split into a separate date column and time column in the access database. Initially I just created a derrived column for the time and set the expression equal to the source date/time column from SQL Server. Unfortunately, that just makes the date column and time column the same having the full date/time.
What expression can I use during a derrived column transformation to assign just the date to a derrived column and just the time to another derrived column?
In order to pull back data from several servers to one central server I need to execute a stored procedure over each remote server. SQL 7 doesn't accept the following syntax when comparing date fields:
hi all, in my sql server 2005 , i 've a table gg containing a column 'date'.its data type is datetime ,null now i want to insert only the date to this field from vb.net page. i dont want "time" to insert in this page. one more thing ,i know varchar will work for what i need but i want to use date time. If anyone who knows how this is possible pls do send me the code. thanks swapna
Hi folks, I posted the following question on comp.databases.ms-sqlserver, bu, to my surprise got no responses. So I wondered if you good people might be able to help us out... ================================================== Our application communicates with SQLServer 7 through ODBC. In order to write date/time fields into the database, it uses either the dt conversion function, or more usually the ts conversion, on a string of the format 'yyyy-mm-dd hh:mm:ss.xxxxxx'. With almost every every other database engine (I think Informix is the only exception), this is accepted and converted into a date format that the back end can store.
With SQLServer 7, any inserts containing dates are dropped because the timestamp conversion isn't working. If I take a copy of the select statement into the query analyser, it reports an error unless I change the timestamp string format from ts 'yyyy-mm-dd hh:mm:ss.xxxxxx' to ts 'yyyy-mm-dd hh:mm:ss.xxx', ie from microsecond to millisecond resolution.
Version 6.5 didn't have this problem, and as I mentioned, nor does any other database engine that our application talks to. ================================================== ===
I have been searching the net to see how to do this. I'm a noobie to DB's and I may have missed it. OK I have a Customer table and what I want to do is have a column with the date and time that the customer was added to the database ( i.e. Customer Since ) also last time that record was edited. Possible??
set @x1 = (select DRfieldname from tblJournalType where journaltypeid = 2 set @SQLstring = 'select ' + @x1 + ' from tblAssettype where assettypeid = 10' set @x2 = EXEC (@SQLstring)
The last line above is where I am getting the error. Is this possible to do this?
Hello, I run the DTS to copy data from Progress to SQL Server. How can match/convert the date variables to check. The field p-date as format 'mm-dd-year' . It has the value of 10/09/2001. The field s-date as varchar format. It has the value 2001-10-09. How can use the where condition ( Select ...... WHERE p-date = s-date.)
hi guys im having real problems and dont know how to solve it at all i have a web app which allows users to enter information through edit boxes when they submit the imformation it gets added into my SQL database. does anyone know how to get the Date and Time when they insert the information and store in another column of type datetime in SQL database the web app is written in C# hope someone can help thanks
I have string as '1-12-2012', i wanted to convert it into date as format '2012-12-01'. I used the function as cast('1-12-2012' as Date) it's working but for a set of values where Null occurs it gives error as conversion failed when casting date and/or time from character string.
Hello all, I'm creating a stored procedure in SQL Server 2000. I'm trying to count how many rows match a certain WHERE clause, and assigning this integer to a variable:
---------------- DECLARE @RowCount int,
SELECT COUNT(*) FROM Customers WHERE FirstName='Joe' ----------------
How can I assign the count that returns from the SELECT statement to the @RowCount?
I have a multitier app running 24 x 7...All is running ok until the server delay too much to respond when I'm trying to add the records, so I start to receive erros from the msdtc and the transaction is aborted...How can I resolved this trouble? I'm not sure if the cause is too long response from the server, but I have noted that in some moments the server is busier than when it's running ok...just for clearing this, my app have a maximum of 5 threads each one create an transactional objects to process the new entry.
Hi All, Iam experiencing lot of errors for users who are accessing from application to the database . ERROR: "timeout occurred while waiting for resources to execute the query"
I wpuld appreciate if you could tell me work around for this problem. Thanks, Reddy
I need an SQL string that inserts the current date into a database. So far I have tried: SQL = "INSERT INTO X (START_DATE) VALUES ('" & Date.Now & "')" mycomm = New SqlCommand(sql, myconn) mycomm.ExecuteNonQuery() However, there is a problem with the SQL command. The problem is related to the date. Is there a way of programatically inserting the current date/time into the SQL database? Language used is VB.
With regards to time zones, daylight savings, and web users, is there a best practice for storing date & time information in a database? For example, my databases are hosted in Time Zone A, but the web users are in Time Zone B. Then, when I create a rss feed (which is displayed in GMT), I add a third time zone into the mix for the same data. To date (no pun intended), I have been entering the date/time data in the time zone of the database server (Time Zone A), and then converting it using an application setting in the web.config file (i.e. TimeZoneBOffset = -1, GMTOffSet = -5). In other words, each time I display a date I calculate what it should be using the time-zone offset in the web.config. This also enables me to account for changes in day light savings, etc. My concerns are three fold: 1. What if I move the database to another server and the time zone changes? 2. Right now the users are in only 1 time zone. If I expand it to several then the offset will have to be by users, which is do-able, but something I haven't had experience with in the past. 3. It is likely more efficient to calculate the time zone once on input into the DB, rather than in each use like I'm doing now. What time zone baseline for insert into the db should I use? Thanks in advance for your help! PS My application is primarily looking at 'smalldatetime' data - down to the 'minute' level.
Greetings,I have an e-timesheet application.i made a function that takes the startdate of the week:public SqlDataReader GetProjectsActive(DateTime SheetDate) { SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]); SqlCommand myCommand = new SqlCommand("GetProjectsActive", myConnection); myCommand.CommandType = CommandType.StoredProcedure; SqlParameter parameterSheetDate = new SqlParameter("@SheetDate", SqlDbType.DateTime); parameterSheetDate.Value = SheetDate; myCommand.Parameters.Add(parameterSheetDate); myConnection.Open(); SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection); return dr; } i run the application and i pass the value 6/1/2008 (date without time) to the GetProjectsActive but what i notice that the storedprocedure adds the current time to the passsed date when it has been executed so some projects will not appear since the startdate and enddate of the project are only dates so i try this solution: parameterSheetDate.Value = SheetDate.Date;and it works finebut my question why the current time has been added to the storedprocedure automatically although i pass only the date 6/1/2008 date????your help is highly appreciated.Best regards.
We are migrating our database from DB2 8 to SQL Server 2005. We have date and time saperate columns in DB2. For example, Date_of_birth, Store_sun_open_time, Store_sun_close_time etc. For date we are using datetime. For time what datatype should we use in SQL Server?