i have to check first the missign dates between dates 1/1/1999 till current date how many dates are missing and for those dates i have set - update quantity=0 for all those missing dates. docdate is datecolumn in saleshsitory and quantity is in salestable.
can anybody help me to solve this problem.
thanks a lot!
i have a db that gets real time min by min datas everyday but sometimes somehow some of those dates did not written into that db and i wanna know which dates are missing? how can i do it?
I am working with a database containing time series data. In many, cases there is missing dates. For example, while there might be a value for 2001-01-01, 2001-02-01, 2001-03-01, there is none for 2001-04-01 and 2001-07-01. i.e. NR Date Value
------------- ------------- --------------- 2365 2001-01-01 67 2365 2001-02-01 111 2365 2001-03-01 2 2365 2001-05-01 23 2365 2001-06-01 85 2365 2001-09-01 26 2365 2001-11-01 543 2365 2001-12-01 32 54 2001-01-01 217 54 2001-03-01 4 54 2001-04-01 2 ... I want dates for each month in year for each NR I would like to replace the missing dates with data from the previous record.
I have a table like FK_ID, Value, Date (here FK_ID is foreign key)this table getting updated frequently by daily bases that means one record per one day(For example in January month it has maximum 31 records or minimum 0 records, in February it has maximum 28 or 29 or minimum 0 records, based on calender year)I need to query this table to get missing dates in between particular monthsfor example for one FK_ID has only 25 records in Jan 2008 month and in Feb 2008 it has 10 records , so i need to get those missing 6 dates from JAN month and 18 dates from FEB monthhow can i query this
I'm using Sql Server 2005, in which I've table like this
USE [Sample] GO /****** Object: Table [dbo].[Table1] Script Date: 06/07/2008 03:10:51 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Table1]( [TimesheetDate] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [EmpID] [int] NULL ) ON [PRIMARY]
INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-07 00:00:00.000',3) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-18 00:00:00.000',3) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-03 00:00:00.000',9) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-04 00:00:00.000',9) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-05 00:00:00.000',9) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-17 00:00:00.000',9) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-18 00:00:00.000',9) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-01 00:00:00.000',10) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-03 00:00:00.000',10) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-03 00:00:00.000',11) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-04 00:00:00.000',11) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-06 00:00:00.000',11) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-07 00:00:00.000',11) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-08 00:00:00.000',11) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-10 00:00:00.000',11) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-11 00:00:00.000',11) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-12 00:00:00.000',11) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-14 00:00:00.000',11) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-03 00:00:00.000',13) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-04 00:00:00.000',14) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-24 00:00:00.000',14) INSERT INTO [Table1] ([TimesheetDate],[EmpID])VALUES('2008-03-03 00:00:00.000',15)
My task is I want to find Missing Dates (Except Saturday, Sunday) for each Employee.
Note: Missing Dates should be Working Days only (Excluding Saturday & Sunday)
I need to find the missing months in a table for the earliest and latest start dates per ID_No. As an example:
create table #InputTable (ID_No int ,OccurMonth datetime) insert into #InputTable (ID_No,OccurMonth) select 10, '2007-11-01' Union all select 10, '2007-12-01' Union all select 10, '2008-01-01' Union all select 20, '2009-01-01' Union all select 20, '2009-02-01' Union all select 20, '2009-04-01' Union all select 30, '2010-05-01' Union all select 30, '2010-08-01' Union all select 30, '2010-09-01' Union all select 40, '2008-03-01'
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?
Today I have got one scenario to calculate the (sum of days difference minus(-) the dates if the same date is appearing both in assgn_dtm and complet_dtm)/* Here goes the table schema and sample data */
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[temp_tbl]') AND type in (N'U')) DROP TABLE [dbo].[temp_tbl] GO CREATE TABLE [dbo].[temp_tbl]( [tbl_id] [bigint] NULL, [cs_id] [int] NOT NULL, [USERID] [int] NOT NULL,
I have a table that has hotel guests and their start stay date and end stay date, i would like to insert into a new table the original information + add all days in between.
I want to know if there is a way to compare dates in the sql statement with dates that I input into a database and todays date. the datatype that I'm using is smalldatetime.The statement I used is:Select Date from Table where Date > 'Today.now'I get an errorCould this be done or is there another approach?
I have a table which records employees'time-off records. There are 6 columns in this TimeOff table. They are RequestID, EmpName, StartDate, EndDate, Type, NumofDays. I have another table which has all the dates from 01/01/1950 to 01/01/2056.
I am trying write a query which lists all the dates between the timeoff startdate and enddate, including the the start and end dates, but my query so far only lists the start and end date in a timeoff record:
SELECT D.[Date], Datename(dw,D.[Date]) AS Weekday FROM Dates D LEFT JOIN TimeOff T ON D.[Date] = T.OffStartDate OR D.[Date] = T.OffEndDate WHERE (OffType = 'Sick Day' AND EmpName = 'Cat White') AND (D.[Date] BETWEEN T.StartDate AND T.EndDate)
Has anyone ever written a function to retrieve all individual dates between two given dates? Using DATEDIFF I can get the number of days between two dates. However I need to iterate through the days to identify weekend and holiday dates. Has anyone ever written a function to do this?
So, if select datediff(d,'07/01/2007','07/15/2007') as NumOfDays returns 14, I'd need to iterate through the 14 days and get the weekends and holidays. Would I have to use a cursor to iterate through the days?
I'm trying to generate this query, that displays Budget Current Year , Actual Current Year and Prior Year Revenue. When It comes to the Budget and Actual everything works fine, however when I try to add the query for the Prior Year I get an error, and I realized that the leap date is causing the error
Here is what I'm trying to generate
InnCodeID Quarterly Monthly Days Period Year BARmRev AARmRev PYRmRev
ADDIS Q1 Jan 1 1 2008 NULL NULL
ADDIS Q1 Jan 1 1 2008 3462.14 5107.65
ADDIS Q1 Jan 1 1 2008 NULL NULL
ADDIS Q1 Jan 1 1 2008 NULL NULL
Here is the error that I'm getting:
Code Snippet
Msg 242, Level 16, State 3, Line 1
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
(4834 row(s) affected)
Here is my Transact-SQL Syntax (summarized because I Couldn't post it):
SELECT
(CASE WHEN (CASE WHEN dbo.Trans.Tr_Dept = '10' AND dbo.Trans.TR_Main = '5120' AND dbo.Trans.tR_sub = '01'
AND Year(dbo.Trans.TR_Date) = Year(dbo.CurrentDate.CurrDate) AND dbo.trans.Datatype = '1'
THEN dbo.trans.Tr_Amount ELSE NULL END) IS NOT NULL THEN
(SELECT Trans1.TR_Amount
FROM dbo.Trans Trans1
WHERE Trans1.TR_Dept = '10' AND TR_Main = '5120' AND TR_Sub = '01' AND trans1.TR_Date = CAST((CAST(Month(dbo.Trans.TR_Date)
AS varchar(2)) + '/' + CAST(Day(dbo.Trans.TR_Date) AS varchar(2)) + '/' + CAST(Year(dbo.CurrentDate.CurrDate) AS varchar(4))) AS datetime)
AND Trans1.TR_Entity = dbo.Trans.TR_Entity AND trans1.datatype = dbo.Trans.DataType) ELSE NULL END) * - 1 AS BARmRev,
--AA Script Here AS AARmRev,
(CASE WHEN (CASE WHEN dbo.Trans.Tr_Dept = '10' AND dbo.Trans.TR_Main = '5120' AND dbo.Trans.tR_sub = '01' AND Year(dbo.Trans.TR_Date)
= Year(dbo.CurrentDate.CurrDate) AND dbo.trans.Datatype = '1' THEN dbo.trans.Tr_Amount ELSE NULL END) IS NOT NULL THEN
(SELECT SUM(Trans1.TR_Amount)
FROM dbo.Trans Trans1
WHERE RIGHT(RTRIM(Trans1.TR_Dept), 2) = '10' AND Trans1.TR_Main = '5120' AND Trans1.TR_Sub NOT BETWEEN '04' AND '05' AND
trans1.TR_Date = CAST((CAST(Month(dbo.Trans.TR_Date) AS varchar(2)) + '/' + CAST(Day(dbo.Trans.TR_Date) AS varchar(2))
+ '/' + CAST(Year(dbo.CurrentDate.CurrDate)-1 AS varchar(4))) AS datetime) AND Trans1.TR_Entity = dbo.Trans.TR_Entity AND
Hi i have a sorted procedure that create a @temp table that return strNomObjet,strNomDescripteur,strReponse,Percentage
I need to calculate the Percentage for strReponse for each strNomDescripteur. strReponse can be = to A,B,C, or D To calculate the Percentage i have no problem my is that something it possible that a certain strNomDescripteur that will have only A,B and D and there no C i need to put 0%.
INSERT INTO @Temp Select te.stdlastn,te.stdfirstn,COALESCE(NULLIF(REPLACE(tr.T3,'*',''),' '),REPLACE(tr.T2,'*','')),tob.Nom,tob.Affichage,td.Nom,td.Affichage fromBulletin.dbo.tblEleves as te INNER JOIN Bulletin.dbo.tblBulletin as tb ON te.stdnumber=tb.NoEtud INNER JOIN Bulletin.dbo.tblNomBull as tnb ON tb.NoBull=tnb.ID INNER JOIN Bulletin.dbo.tblSection as ts ON ts.ID_Bull = tnb.ID INNER JOIN Bulletin.dbo.tblObjetas tob ON tob.ID_Sec = ts.ID INNER JOIN Bulletin.dbo.tblDescripteur as td ON td.ID_Obj = tob.ID INNER JOIN Bulletin.dbo.tblReponse as tr ON tr.ID = tb.ID whereintActif = 1 and tb.NoBull not like '%EdPhy%' and tnb.Nom not like '%EdPhy%' and tnb.Date = '2006-2007' and te.STDGRADeID = 3 and te.schoolid = '1202' and ts.Nom = 'MATHÉMATIQUES' and tr.[Desc] = td.ID and tr.T2 <> 'NULL' and tr.T3 <> 'NULL' and (tr.T2 <> '' OR tr.T3 <> '') ORDER BY tob.Affichage,td.Affichage
SELECT t1.strNomObjet,t1.strNomDescripteur,t1.strReponse, t1.ReponseCount * 100.0/t2.PersonCount AS Percentage FROM ( SELECT strNomObjet,strNomDescripteur,strReponse,count(*) AS ReponseCount FROM @Temp GROUP BY strNomObjet,strNomDescripteur,strReponse)t1 INNER JOIN (SELECT strNomObjet,strNomDescripteur,count(*) AS PersonCount FROM @Temp GROUP BY strNomObjet,strNomDescripteur)t2 ON t2.strNomObjet=t1.strNomObjet AND t2.strNomDescripteur=t1.strNomDescripteur
This will give this result : As you can see it always A,B,C,D A,B,C,D
Except for "FORMES utilise les transformations géométriques pour" it only A,B,C there no D. So is there a way that i could insert D = 0 So if i don't find any A,B,C or D for certain strNomDescripteur put that letter = 0
Thanks for your help in advance!!
FORMES utilise la mesure pour résoudre des problèmesA 47.222222222222 FORMES utilise la mesure pour résoudre des problèmesB 38.888888888888 FORMES utilise la mesure pour résoudre des problèmesC 8.333333333333 FORMES utilise la mesure pour résoudre des problèmesD 5.555555555555 FORMES utilise les figures géométriques pour résoudre A 61.111111111111 FORMES utilise les figures géométriques pour résoudre B 25.000000000000 FORMES utilise les figures géométriques pour résoudre C 11.111111111111 FORMES utilise les figures géométriques pour résoudre D 2.777777777777 FORMES utilise les transformations géométriques pour A 62.857142857142 FORMES utilise les transformations géométriques pour B 28.571428571428 FORMES ET ESPACE (géométrie)utilise les transformatC 8.571428571428 NOMBRE ET OPÉRATIONSdémontre une compréhension A 69.444444444444 NOMBRE ET OPÉRATIONSdémontre une compréhension B 16.666666666666 NOMBRE ET OPÉRATIONSdémontre une compréhension C 5.555555555555 NOMBRE ET OPÉRATIONSdémontre une compréhension D 8.333333333333
Hello all,I hope someone can help me; if got a value in a cell (040 1234567),when I run a queryin the Analyser I got as respons only 40 1234567, so missing the zero(0) not the whole number is displayed. When I run a query on a cellwith value 1234567 I received the number 1234567 and that's oke. TheData Type of the Column is Char.Thanks,Marko
When I log in to Windows (XP Pro SP2), I get the following message displayed in the Application Event Viewer.
"The ASP.NET DLL (Path: C:WINDOWSMicrosoft.NETFrameworkv2.0.40607aspnet_isapi.dll) (Version:2.0.40607.0) is missing"
The message is quite correct in its assertion that the file is not where it says it is. There is a copy of the noted DLL however, in C:WINDOWSMicrosoft.NETFrameworkv2.0.50727 and in C:WINDOWSMicrosoft.NETFrameworkv1.1.4322
Why is the Report Server looking for that particular version? Why can't it point at the later version?
I'm trying to access some files on a file server in CLR code and I have to impersonate the windows login to get permission. I am using the classic example of SqlContext and i can see that after calling the impersonate method it changes. I always get false from the System.IO Direcotry and File functions to see if there are any files or even if the directory exists. The permissions are correct on the file share and the batch submission is using the correct login.
When I sign on to my computer I get this message, MSVCR70.dll can not be found try to reinstall it this may fix the problem, BUT CAN'T find the dll that is missing to reinstall it, HOW DO I FIX THIS please HELPPPPPPPPP!!!!!!
I have a normal nvarchar(50) field in a table that has a single comma in it but when i read it using OleDbDataReader the comma gets removed. any ideas what i am doing wrong ?
Hi guys need some help, someone has given me some code to help me filter a gridview by the surname field by the selected letter of a dropdown list. My code is below, however if i select a letter from the dropdown and click the button i get an error, can someone take a look please. <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
<script runat="server"> Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim dset As New Data.DataSet Dim dview As New Data.DataView dview.Table = dset.Tables("modelRegistration1") dview.RowFilter = "surname LIKE" + surnameFilter.SelectedValue.ToString() + " % " GridView1.DataSource = dview GridView1.DataBind() End Sub </script>
error message is Server Error in '/KayKay' Application.
Syntax error: Missing operand after 'LIKEC' operator. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SyntaxErrorException: Syntax error: Missing operand after 'LIKEC' operator.Source Error:
Line 6: Dim dview As New Data.DataView Line 7: dview.Table = dset.Tables("modelRegistration1") Line 8: dview.RowFilter = "surname LIKE" + surnameFilter.SelectedValue.ToString() + " % " Line 9: GridView1.DataSource = dview Line 10: GridView1.DataBind()Source File: E:InetpubwwwrootKayKayAdminupdateModels.aspx Line: 8 Stack Trace:
In the console, when right clicking on a table name...then selecting 'open table', the toolbar at the top of the page is not displaying. This is the graphical bar with the 'SQL' button that lets you filter the results.
Recently I installed MSDE and then Analysis services and also applied SP3's for both...
However I have noticed that the FoodMart Database which was automatically installed previously with Analysis services is not installed. Is there any way to get that?
I need to build a results grid that reports totals or zero for an attribute
SELECT ClaimType, VendorNumber, COUNT (ClaimNumber) AS ClaimCount FROM ClaimHeader GROUP BY VendorNumber, ClaimType ORDER BY VendorNumber ASC;
THe underlying data has two claim types (UB, and HCFA). Some vendor numbers have only UB claims or only HCFA claims. I want my totals to show a zero for those vendor numbers. Example
My current group by doesn't give me the 3rd row in my example. How do I change my query to add those rows that have no claims as a zero. Put another way, every vendorNumber has to report a HCFA total and a UB total, even if they're zero.
I have encountered an issue with one of my log files which has me somewhat puzzled. I receieved notification at 00:02:16:36 that the Log file was full: The log file for database 'TDS' is full. Back up the transaction log for the database to free up some log space.. A large number of these same messages have followed.
Prior to these messages starting the log file was backed up successfully at 00:00:01:10 Shortly after this there is a message - and this is the bit that confuses me - at 00:02:16:35 that says: d:mssqldata ds_log.ldf: Operating system error 112(error not found) encountered.
So from what I can tell the log file was backed up successfully. Then approx 1 minute later the system can't find the log file??? Then I keep getting these log file full messages - until the next log backup (60 min later)...then everything is fine. HUH?
When looking at the log file for SQL it is sitting there, and isn't new, as it's created date is back when I setup the database initially.
Can anyone shed any light on what this message might mean and whether there is specifically something that I can do to circumvent it in the future.
Oh yeah we have nothing tricky in terms of replication or log shipping or anything like that.....
Hi all, I would greatly appreciate a boost with this problem. I'm trying to 'script' the mundane task of adding descriptions to my tables (I know this can be done from Enterprise manager via Diagrams, but I have a huge (did I mention huge?) amount of tables and I really don't want to have to go to the properties of each and every table.
Now, if I read BOL right I can use sp_addextendedproperty (and here is their example):
sp_addextendedproperty 'Caption', 'Caption Test Table', 'user', dbo, 'table', TestExProp <--- Does this not add a description to the the table?
Well, I tried it and No Joy ! When I look at the table properties from the Diagram (w/in Enterprise Manager) I have a nice big EMPTY Description Box. I tried changing it from 'Caption' to 'Description' thinking that would work but alas, I sit here and wonder where I went wrong ....
What have I missed?
Any input would put me out of my misery and make me a productive individual (at least for today !)
I installed SQL server 2005 on a win2003 server box.
When I open the Connect to Server dialog box, I choose server type: Database Engine. There is no Servername listed, so I put in the name of the PC.
I get a long error message when I try to connect:
Cannot connect to PCName.... ...error: 40 - Could not open a connection to SQL Server)...
When I try to go into the Surface area Configuration, I get this message: "No sql server 2005 components were found on the specified computer. Either no components are installed, or you are not an administrator on this computer. (SQLSAC)"
I am logged in as Administrator in the PC, so did I do something seriously wrong with the installation?
In the services window, I can not fine MSSQLserver (not sure if this is relevant).