|
How about subtracting count of leaves from endDate
like
SELECT @SDate = DATEADD (day, - @holidayCount, @endDate)
|
|
|
|
|
Hi,
select empcode,name,(counts+2) as leaves from (select a.empcode,b.name,count(*) as counts from tbl_leaveentry a,tbl_emp b where a.empcode=b.empcode and a.empcode='EMP001' and
a.entrydate between DATEADD(d,-2,'12/8/2011') and '12/8/2011'
group by a.empcode,b.name) as c where (counts+2) =3
The above code generates the report of the employee who have taken leave more than 3 days from the selected dates but i need to get the start date of the leave applied by the employee
eg: 12/1/2011 to 12/8/2011
Thanks in advance
|
|
|
|
|
What other fields are in tbl_leaveentry besides empcode,entrydate?
Do you have a field that indicates how may leave days were taken? There should be a field that indicates how many days were taken for leave.
Just at glance, it seems to me that your database was poorly designed. I think start date should have been included in the first place.
|
|
|
|
|
Hello .
I have a web service which takes some parameters and inserts them in another database . I have my own database that has a
table (Table_B) .Now
I want to call my web service when a new record inserts to (Table_B)
I know that i should use a trigger . All I want to do is calling a web service inside of my trigger . I don't know how to call it.
Would you please help me
Thanks .
bye
|
|
|
|
|
If I was you I would start here:
www.google.com[^]
Type sql server call web service from trigger and press Enter. That gives over 2 million links, at least one of them must be useful.
P.S. one of those links is to an article here on Code Project. In the article it actually says:
The truth is it's not good to access a web service trought a trigger, due to performance concerns.
I'm sure you can make your own mind up as to whether that is true or not.
|
|
|
|
|
Hi
Thanks for your Guidance. I know all of them but thanks
|
|
|
|
|
If I may ask, what inserts records in table_B; is it a stored procedure?
If so, I would use the same stored procedure to call the web service immediately after it inserts data. I don't know if ordinary stored procedures can call web services so I would suggest an extended stored procedure i.e. a CLR dll.
I haven't done anthing like it; so I am really just guessing.
|
|
|
|
|
I exported my results data into Excel 2007 (784,000 records on one column) so that I can Import it back into SQL Server 2008 as a table. When the data comes back from Excel it comes in as a float which I convert to a nvarchar(255) or varchar(50), but any record that has a letter in it shows up as NULL in SQL Server 2008. I have tried all combinations. Can anyone suggest anything?
Ed
|
|
|
|
|
Try yo convert float Excel column into text and then import in SQL Table.
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
Hi All,
Iam new to database. Here iam using sql server 2000. i want to sum the counts from two different tables. I need this to calculate the employees who have taken continuous leaves in a week/month.
Example: I have three table such as
Table1:tbl_attandence(it contains the employee id and the intimings and outtime)
Fields:empcode,intime,outime
Eg: EMP001,11/24/2011 09:30:45 AM,11/24/2011 04:30:15 PM
Table2:tbl_leaveentry(it contains the leave dates taken by an employee)
Fields:empcode,entrydate
Eg: EMP001,11/25/2011
Table3:tbl_holidays(it contains the list of holidays such as sunday,saturday,chrismas,newyear....)
Fields:holidays,days
Eg: 11/25/2011,sunday
I am attaching my code such that it return the sum but iam unable to return the employee name and id because it is showing the result as null as the holidays does not match
please help me in completion of process
select sum(counts)
from(
select a.empcode as empcode,b.name,count(*) as counts from tbl_leaveentry a,tbl_emp b
where a.empcode=b.empcode
and a.empcode='EMP001'
and a.entrydate between '11/24/2011'; and '11/27/2011'
group by a.empcode,b.name
union
select null,null,count(*) as counts from tbl_holidays
where holidays between '11/24/2011' and '11/27/2011'
) as c having sum(counts)>=3
the above code returns correct sum but if i add name before the sum and execute the result is not been summed because holidays does not match with the leaves
Please suggest that how can i do this task any help will be appreciated
|
|
|
|
|
Try something like:
select name, sum(counts)
from(
select a.empcode as empcode,b.name,count(*) as counts
from tbl_leaveentry a
INNER JOIN tbl_emp b
ON a.empcode=b.empcode
where a.empcode='EMP001'
and a.entrydate between '11/24/2011'; and '11/27/2011'
group by a.empcode, b.name
union
select null, null, count(*) as counts
from tbl_holidays
where holidays between '11/24/2011' and '11/27/2011'
) as c
GROUP BY name
having sum(counts)>=3
Note the GROUP BY and I have changed to an INNER JOIN.
Hope this helps. Sorry, I do not have time to dive deeper into this.
[edit]to spell note correctly[/edit]
modified 14-Dec-11 15:19pm.
|
|
|
|
|
Try this.
DECLARE
@holidayCount AS int,
@startDate AS datetime,
@endData AS datetime,
@empCode AS VARCHAR(20)
SET @startDate='11/24/2011 00:00:00.000'
SET @endDate='11/27/2011 23:59:59.997'
SET @empCode='EMP001'
SET @holidayCount=(SELECT COUNT(*) FROM tbl_holidays WHERE
holidays BETWEEN @startDate AND @endDate)
SELECT empCode, name, (Counts + @holidayCount) As holidayCounts
FROM
(
SELECT a.empCode, b.name, (Count(*) as Counts
FROM tbl_leaveentry a,tbl_emp b
WHERE a.empCode=b.empCode AND
a.empCode=@empCode AND
a.entryDate @startDate and @endDate
GROUP BY by a.empCode,b.name
) AS temp
WHERE Counts + @holidayCount>3
|
|
|
|
|
Hi SilimSayo,
Thank you so much for the query it matches my result perfectly.
|
|
|
|
|
|
Hi everyone! How do I grant a server role permission to create users? I previously added database administrators to the 'sysadmin' server role and they were able to create users. I also changed the schema of my tables but now the schema for the 'sysadmin' role cannot be changed from 'dbo' to the one I created. One way to let them access tables is to prefix my tables with the schema name but there are lots and lots of code to do this.
I moved the administrators to the 'securityadmin' server role and they are able to use tables without prefixing table names with the schema name. But now they are only able to create logins but cannot create users as an error is reported that the user does not have permission to do it.
I would like to know how I can grant the 'securityadmin' role permission to create users so that I will not have to prefix my table names with the schema name if they should remain in the 'sysadmin' role as editing the code at this point for this will likely cause problems. Thanks in advance.
|
|
|
|
|
The type of the database (and the version) is essential when asking this level of information as the security functionality varies between database systems.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm using SQL Server 2005, Stanndard Edition. I've googled for long and still not getting any solution.
|
|
|
|
|
Hello,
I will be creating a process that imports time series data from CSV files into an MSSQL database. After the data from the CSV file is processed, the CSV file is moved to an archive folder. If there are multiple CSV files in the processing folder, the process will import them as a batch.
The name(s) of the CSV file(s) will include date information.
At the start of a new day, a new CSV file will be created, I'll use some kind of naming convention for the file to indicate what date it's for. During the day, the CSV file will be appended to.
I am pondering whether I should:
- Create a SSIS task to perform this process, and schedule it to run every X minutes
- Create a C# Console application that monitors the processing folder, for mods to an existing file, and additional .csv files (for batch processing)
What do you think the advantages/disadvantages of either approach are? Which one would you use? Also, can I use LINQ in any way to read the CSV data?
I'm using MSSQL 2005.
Thanks a lot for any pointers/suggestions/best practices.
Richard Rogers
|
|
|
|
|
This is purely a business decision and should not be answered by the developer.
We have done both, for different requirements, and I am still ambiguous as to which is the best solution. Except I would never create a console app, ours is winform so the user can interact with the process.
One thing I have learned over the years is NOT to use ETL but to move the T (transform) to after the load so we build ELT processes.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: so we build ELT processes.
Agreed.
|
|
|
|
|
|
|
Mycroft, Jörgen, and David,
Thank you all for your responses.
This is a short project for a small consulting firm. I am the only coder, and I'm afraid to say I'm also the business analyst.
The issues I perceive are:
1. Using SSIS 2005, I cannot "monitor" a folder for new or updated CSV files. The File System Task component does not appear to be capable of doing this.
2. I have written a very simple SSIS package to copy the data from a csv file with a fixed file name. Even if there were a component that monitors a folder with a filemask like (*.csv), how would I pass the filename to the Flat File Source component?
3. I would only want to move the csv file to the archiving folder if the import of the data completed with a return code of zero, which includes calling a stored proc on the server. What is the standard way of informing the user that an error occurred in a SSIS task?
Is all this possible in a SSIS package?
Thanks,
Richard
|
|
|
|
|
I cannot contribute to the SSIS solution because I have no experience with it.
I guess even developing a Console Application is outside your comfort zone? A data importer really wouldn't take much to develop.
It wouldn't be pretty, but once you write it, you could use windows scheduler to check the directory every few minutes.
|
|
|
|
|
Hi David,
I'm actually very inclined to write a console app, or maybe even a service.
It's the guy who is directing my work who is kind of against it, for no apparent reason.
I don't have the capability of writing the code at the Client site, where I'm working.
I do have VS 2010 installed here at home though, so I may give it a whirl.
I tend to think that it would be pretty! A simple and elegant solution.
Thanks!
|
|
|
|