.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

query wich returns records for each day between start date from table 1 and mutation dates in table

Posted By:      Posted Date: October 05, 2010    Points: 0   Category :Sql Server


I have to tables with dates, table Employments with all employements of all employees, with start date and end date, and a table Mutations with mutations (e.g in salary) with start dates.

Now I try to write a query which returns a record for each day an employee is in employment, with the correct salary. SO at first, it should return all days between the employment start date and the first mutation date, then the number of days between the first mutation date and the second mutation date etcetc, and at last the number of days between the last mutation date and the employment end date. The number of mutations varies for each employment, and employees cna have multiple employments (history, so not at the same time) in the employments table.

How to do this?

View Complete Post

More Related Resource Links

expand table with date range for each dates




         I have a scenario to expand the resultant table with dates column,.


For ex:

select patientid, patientname, servicefrom, serviceto from appointment

will result the following table


patientid      patientname      servicefrom      serviceto

  a1                alex               02/05/2010       02/08/2010

  a2                brad              02/09/2010        02/09/2010

  a1                alex               02/07/2010       02/10/2010


i want to write a query to expand the tables like


patientid      patientname      servicefrom      serviceto           eachdates

  a1                alex               02/05/2010       02/08/2010      02/05/2010


How filter data from a webservice that returns a table by comparing dates


I have an infopath form that takes in brings in an entire table and I want to filter it on datetime by comparing records from a time span of dates that have already been assigned.  I have tried everything from doing it from the within infopath using equations to filter the datasource and also doing it programmatically.  I am to the point where I think it has to be done programmically (C#).  Here is an example of the XPath code I was trying:

(xdMath:Avg(xdXDocument:GetDOM("ISSOrbits")/dfs:myFields/dfs:dataFields/d:ISSOrbits/@Apogee[(number(translate(xdXDocument:GetDOM("ISSOrbits")/dfs:myFields/dfs:dataFields/d:ISSOrbits/@StartTime, "T-:+", "")) >= number(translate(/my:myFields/my:MissionData/my:LaunchMissionDateTime, "T-:+", "")))]))

It seem that only the first record (node) from ISSOrbits gets compared and not the whole dataset.

Please show me how to do this programmatically in C# or if there is way to do it without code.


Charles Picco

P.S. I forgot to mention that table is brought in through a webservice that cannot filter data.


Query a Table with Japanese Characters returns always 0 results


Hi all, I wonder if you could give me a hand on this please...

I've a table (lets say with 2 columns: ID int, Vendor Name nvarchar(255)) with some records with Japanese Characters. 

When I try to query that table for the specific rows with Japanese string I always get 0 results.


Table example:


ID Vendor Name

1 Bruno Ferreira

2 ??????????


Query Example:

select * from myTbl where [Vendor Name] collate <<collations name>> = '??????????'


Result always nothing...


I've tried with all the possible available collations but with no luck

collations I've tried:











query table row for several records.


not sure if this is the correct forum..but...I'm using VS2008 and have a sql query on a button click...

my question is....

is there a way to query my database for more than one record at a time?

 - i.e. "select * from mytable where myrow = "' & textbox1.text & "'"

and have more than one thing i'm looking for in that textbox?

like if the textbox contained


could it find all records in that row that are 1 and 2 and 3 and 4 ?

not sure if that is exactly clear, but thanks for any help.


lookup table query


we are doing our cms migration. both cms's have their own articleID/contentID, we have a lookup table that contain the article URL and its content id.  Now we want to query that table on every single click to get its respective id. 

How and where i can implement this?

Create Table from MDX query

Hi,I want create a table from the result of the MDX query. When I finish the wizard of import data in SQL Server Environment. at the last stage, the error is : Pre-execute (Error) Messages Information 0x4004300b: Data Flow Task 1: "component "Destination - Query" (31)" wrote 0 rows.(SQL Server Import and Export Wizard) please guid  me.Thank you a lot.Naeimeh

Application to Constantly query Table Values and Refresh with most recent value

Hello, I must apologize in advance because I am not sure if this is the correct place for this question. I am looking for ideas on how to build an application that in the most basic sense contains a field with the most current data from a table in a SQL Server database (this would be based off of a datetime timestamp in the table). I am new to this kind of problem and am unsure where to start looking for solution ideas. The table value updates variably and could possibly update every second to every hour. I would like to design an application that would be lightweight to both the server and the user's machine. This would take the place of an unneeded report on my Reporting Services server. Any and all suggestions would be welcome because I am not sure of options I even have on this. Thanks in advance for your time and consideration, Matt

Transact-sql - tricky query to get a list of people from a table where i belong too.

I've no idea how to manage and optimize this query: I've four table. - User (userId, name) - Member (memberId, name, ownerId) The ownerId = user.userId - PresentPeople (activityId, presentId, ...) so presentId = memberId - Activity (activityId, ownerId, startDate...) and ownerId = user.userId So here for an user, I need members created by this user, and for this members I need the list of presentPeople for the activity that theyjoined. But I don't know how to get this list because they are in the list. Not sure if i'm clear there, Big help would be very helpfull :)) thanks

How to insert the Current date and time in to SQL Table..

Hello Members,              I have create the table as per the following ..create table company(  empname varchar(30),  empid int,  joindate smalldatetime)I tried,insert into table values('Kumar',202, ??????)I want to insert Current date and time into table Company.....Please give me the solution...Thanks.. 

SSRS Table hide duplicate by date

Hi, I am parikshit deshpande i am working in SSRS 2005 from last three months. I am trying to solve this problem please help me for that, I have one table as per  Date                     Shift                               Tons                       Passes 1/1/2009            Day                                    Formula                  Formula 1/1/2009           Swings                            1/2/2009           Day 1/2/2009     &nb

Duplicate records find in table

  Hi ALL, I want to find the dynamically check the primary key values and remove the duplicate records.. please suggest it.   Regards Ram

sql server query get a list of a table

Hi guys, I've a hard query to manage ... I need to get for a report the number of required people to an appointment, but this query works but just for the regarding person related to the appointment. SELECT CRMAF_FilteredContact.OwnerID ,CRMAF_FilteredContact.OwnerIDname ,SU.businessunitidname ,SU.eu_reporthubname -- ,SU.eu_reportcountryidname ,CRMAF_FilteredContact.ContactID ,CRMAF_FilteredContact.FullName ,CRMAF_FilteredContact.invoke_tiername ,CRMAF_FilteredAppointment.ActivityID ,CRMAF_FilteredAppointment.RegardingObjectID ,CRMAF_FilteredAppointment.Subject ,AP.ActivityPartyID ,AP.PartyID ,case when CRMAF_FilteredAppointment.ActivityID is null then null else CRMAF_FilteredContact.ContactID end as s_contactsvisited -- # of contactsvisited FROM FilteredContact CRMAF_FilteredContact JOIN FilteredSystemUser SU ON CRMAF_FilteredContact.ownerid = SU.SystemUserID <strong> LEFT JOIN FilteredActivityParty AP ON ( AP.PartyID = CRMAF_FilteredContact.ContactID or AP.PartyID = CRMAF_FilteredContact.OriginatingLeadId) AND AP.participationtypemask = '8' -- regarding</strong> LEFT JOIN FilteredAppointment CRMAF_FilteredAppointment ON AP.ActivityID = CRMAF_FilteredAppointment.ActivityID AND CRMAF_FilteredAppointment.ownerid = SU.SystemUserID AND CRMAF_FilteredAppointment.stat

Selecting different no. of records from the same table

Hello all, This might seem a basic thing but bothering me from last few days. Suppose I have a table containing 5 million records and I am running queries one by one (one query executes completly and then next query is fired)as below on that table. SELECT top 20000 FROM MyTable SELECT top 200000 FROM MyTable SELECT top 2000000 FROM MyTable  Now my questions are; Will SQL Server use same execution plan? As I am running these queries one by one in same order as given above, will second query take less time than it should if run standalone (only second query is fired, no query fired before that) and similarly will third query take less time than it should if run standalone (only third query is fired, no query fired before that), since there is a possibility of same execution plan being used?  Regards.    

Display specific table from the start vs selecting from a list.

Hello all, I'm using VS2010, EF 4.0. I want to display a list view from a specific table from the start -instead of the standard default page that list all the tables. Any ideas are welcome. 

I have relation many to many - how can I delete records from intermediate table ?

I have tables: Books id title Authors id name BooksAuthors book_id author_id Entity Framework generated only models for tables Books and Authors in relation many to many. How can I delete from table BooksAuthors all records where book_id =5 ?

Get the count of the recently added records to a table

i need to create 2 temporary tables. The records inserted into the 2nd table is the same as that from table1. Now, i am inserting some other records into table 2.what i need is, to retrieve the count of the recently added records into table2.How to achieve this? 

T-SQL 2005 table query

Hi, I have SQL 2005 table like below one declare @OrderTable TABLE (OrderID varchar(10),OrderValue decimal(10,2),OrderDate DateTime) INSERT INTO @OrderTable VALUES('P06',25.22,'2010-01-24') INSERT INTO @OrderTable VALUES('P06',25.22,'2010-01-24') INSERT INTO @OrderTable VALUES('P06',25.22,'2010-01-24') INSERT INTO @OrderTable VALUES('P06',25.22,'2010-01-24') INSERT INTO @OrderTable VALUES('P06',25.22,'2010-01-24') INSERT INTO @OrderTable VALUES('P06',455.85,'2010-01-24') INSERT INTO @OrderTable VALUES('P06',866.45,'2010-01-25') INSERT INTO @OrderTable VALUES('P06',749.61,'2010-01-28') INSERT INTO @OrderTable VALUES('P01',755.61,'2010-02-23') INSERT INTO @OrderTable VALUES('P01',755.61,'2010-02-23') INSERT INTO @OrderTable VALUES('P01',755.61,'2010-03-23') Final result I am looking for is SET NULL value in SELECT query Whenever Same OrderID and OrderDate is found... OrderID  OrderValue   OrderDate P06         25.22   2010-01-24 P06        NULL             2010-01-24 P06      NULL             2010-01-24 P06        NULL             2010-01-24 P06      NULL              2010-01-24 P06 &
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend