How to replace a dates on a SQL query on Visual Studio (and get the query to work in there in the first place)?

Morning all,
I've just been assigned a report-related project but I have not created much of anything in C# or .Net before!
I was wondering if someone could help me get started. Here are the specifications:
Basically, I am to create an automated report application. I have the query and I will include it further down
in this post. The page is to have a couple blanks to specify the Start Date and End Date and replace those dates in the query, and generate the report. What I need some help on is how to make the SQL query work in the application which I will connect to the
intended database to generate the report (basic I know, but I'm new at this) on Visual Studio 2010. I also need some help on programming the Start Date blank and End Date blank so that what the user types in for those blanks will replace the date fields in
the SQL query, then generate the report with the new dates. 
I appreciate the help!
The SQL query and what the dates are replacing:
select 
PTH.INST_ID ,
PTH.EMPLOYEE_ID,
DBH.HR_DEDUCTION_AND_BENEFITS_CODE,
replace(DB.DESCRIPTION,',',''),
DB.WITHHOLDING_LIABILITY_ACCOUNT_MASK,
DBH.HR_DEDUCTION_AND_BENEFITS_ID,
DBH.CHECK_DATE,
DBH.CHECK_NO,
DBH.FIN_INST_ACCT_ID,
replace(replace (DBH.COMMENT,CHAR(10),' '),CHAR(13),' '),
DBH.HR_DEDUCTION_AND_BENEFIT_CYCLE_CODE,
DBH.LENGTH,
DBH.EMPLOYEE_COMPUTED_AMOUNT,
DBH.EMPLOYEE_BANK_ROUTING_NUMBER,
DBH.EMPLOYEE_ACCOUNT_TYPE,
DBH.EMPLOYEE_ACCOUNT_NUMBER,
DBH.EMPLOYER_COMPUTED_AMOUNT,
DBH.EMPLOYEE_GROSS_AMOUNT,
DBH.EMPLOYER_GROSS_AMOUNT,
DBH.PAYROLL_EXCLUDE,
PTH.VOID_DATE,
PTH.BATCH_QUEUE_ID,
B.BATCH_CODE,
BQ.FY,
BQ.END_DATE,
BQ.COMMENTS,
BQ.BATCH_CRITERIA_USED,
BP.COLUMN_VALUE,
PTH.REPLACEMENT,
P.LAST_NAME,
P.FIRST_NAME,
P.MIDDLE_NAME
from PY_EMPLOYEE_TAX_HISTORY PTH
INNER JOIN PERSON_EMPLOYEE PE ON
PE.INST_ID=PTH.INST_ID AND
PE.EMPLOYEE_ID=PTH.EMPLOYEE_ID
INNER JOIN PERSON P ON
PE.INST_ID=P.INST_ID AND
PE.PERSON_ID=P.PERSON_ID
LEFT JOIN HR_EMPLOYEE_DEDUCTIONS_AND_BENEFITS_HISTORY DBH ON
PTH.INST_ID=DBH.INST_ID AND
PTH.CHECK_DATE=DBH.CHECK_DATE AND
PTH.CHECK_NO=DBH.CHECK_NO AND
PTH.EMPLOYEE_ID=DBH.EMPLOYEE_ID
LEFT JOIN HR_DEDUCTION_AND_BENEFITS DB ON
DB.INST_ID=DBH.INST_ID AND
DB.HR_DEDUCTION_AND_BENEFITS_CODE=DBH.HR_DEDUCTION_AND_BENEFITS_CODE
LEFT JOIN BATCH_QUEUE BQ ON
PTH.BATCH_QUEUE_ID=BQ.BATCH_QUEUE_ID
LEFT JOIN BATCH B ON
B.BATCH_CODE=BQ.BATCH_CODE 
LEFT JOIN BATCH_PARAMETER BP ON
BQ.BATCH_QUEUE_ID=BP.BATCH_QUEUE_ID
AND BP.COLUMN_NAME = 'SUPPRESS_DIRECT_DEPOSIT'
------Please change the WHERE condition for date range of the month you need to run this for.
WHERE PTH.CHECK_DATE >='07/01/2013'
AND PTH.CHECK_DATE <='07/31/2013'
and BQ.BATCH_CODE='BAT_PY_PAYCALC'
and bq.fy=2014
ORDER BY PTH.INST_ID ,
PTH.EMPLOYEE_ID,
DBH.HR_DEDUCTION_AND_BENEFITS_CODE,
DBH.CHECK_DATE

Try this code.  The Server name will be the same name when you use SQL Server Management Studio (SSMS).  It is in the login window for SSMS.  I assume you are using SQLSTANDARD (not SQLEXPRESS) which is in the connection string in the code
below. I also assume you have remote connection allowed in the database.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication1
class Program
const string DATABASE = "Enter Database Name Here";
const string SERVER = "Enter Server Name Here";
static void Main(string[] args)
DateTime startDate = DateTime.Parse("07/01/2013");
string startDateStr = startDate.ToString("MM/dd/yyyy");
DateTime endDate = new DateTime(startDate.Year, startDate.Month + 1, 1).AddDays(-1);
string endDateStr = endDate.ToString("MM/dd/yyyy");
string connStr = string.Format("Server={0}\\SQLSTANDARD;Database={1};Trusted_Connection= True;", SERVER,DATABASE);
string SQL = string.Format(
"select\n" +
" PTH.INST_ID\n" +
",PTH.EMPLOYEE_ID\n" +
",DBH.HR_DEDUCTION_AND_BENEFITS_CODE,\n" +
",replace(DB.DESCRIPTION,',','')\n" +
",DB.WITHHOLDING_LIABILITY_ACCOUNT_MASK\n" +
",DBH.HR_DEDUCTION_AND_BENEFITS_ID\n" +
",DBH.CHECK_DATE\n" +
",DBH.CHECK_NO\n" +
",DBH.FIN_INST_ACCT_ID\n" +
",replace(replace (DBH.COMMENT,CHAR(10),' '),CHAR(13),' ')\n" +
",DBH.HR_DEDUCTION_AND_BENEFIT_CYCLE_CODE\n" +
",DBH.LENGTH\n" +
",DBH.EMPLOYEE_COMPUTED_AMOUNT\n" +
",DBH.EMPLOYEE_BANK_ROUTING_NUMBER\n" +
",DBH.EMPLOYEE_ACCOUNT_TYPE\n" +
",DBH.EMPLOYEE_ACCOUNT_NUMBER\n" +
",DBH.EMPLOYER_COMPUTED_AMOUNT\n" +
",DBH.EMPLOYEE_GROSS_AMOUNT\n" +
",DBH.EMPLOYER_GROSS_AMOUNT\n" +
",DBH.PAYROLL_EXCLUDE\n" +
",PTH.VOID_DATE\n" +
",PTH.BATCH_QUEUE_ID\n" +
",B.BATCH_CODE\n" +
",BQ.FY\n" +
",BQ.END_DATE\n" +
",BQ.COMMENTS\n" +
",BQ.BATCH_CRITERIA_USED\n" +
",BP.COLUMN_VALUE\n" +
",PTH.REPLACEMENT\n" +
",P.LAST_NAME\n" +
",P.FIRST_NAME\n" +
",P.MIDDLE_NAME\n" +
" from PY_EMPLOYEE_TAX_HISTORY PTH\n" +
" INNER JOIN PERSON_EMPLOYEE PE ON\n" +
" PE.INST_ID=PTH.INST_ID AND\n" +
" PE.EMPLOYEE_ID=PTH.EMPLOYEE_ID\n" +
" INNER JOIN PERSON P ON\n" +
" PE.INST_ID=P.INST_ID AND\n" +
" PE.PERSON_ID=P.PERSON_ID\n" +
" LEFT JOIN HR_EMPLOYEE_DEDUCTIONS_AND_BENEFITS_HISTORY DBH ON\n" +
" PTH.INST_ID=DBH.INST_ID AND\n" +
" PTH.CHECK_DATE=DBH.CHECK_DATE AND\n" +
" PTH.CHECK_NO=DBH.CHECK_NO AND\n" +
" PTH.EMPLOYEE_ID=DBH.EMPLOYEE_ID\n" +
" LEFT JOIN HR_DEDUCTION_AND_BENEFITS DB ON\n" +
" DB.INST_ID=DBH.INST_ID AND\n" +
" DB.HR_DEDUCTION_AND_BENEFITS_CODE=DBH.HR_DEDUCTION_AND_BENEFITS_CODE\n" +
" LEFT JOIN BATCH_QUEUE BQ ON\n" +
" PTH.BATCH_QUEUE_ID=BQ.BATCH_QUEUE_ID\n" +
" LEFT JOIN BATCH B ON\n" +
" B.BATCH_CODE=BQ.BATCH_CODE\n" +
" LEFT JOIN BATCH_PARAMETER BP ON\n" +
" BQ.BATCH_QUEUE_ID=BP.BATCH_QUEUE_ID\n" +
" AND BP.COLUMN_NAME = 'SUPPRESS_DIRECT_DEPOSIT'\n" +
" WHERE PTH.CHECK_DATE >='{0}'\n" +
" AND PTH.CHECK_DATE <='{1}'\n" +
" and BQ.BATCH_CODE='BAT_PY_PAYCALC'\n" +
" and bq.fy=2014\n" +
" ORDER BY PTH.INST_ID\n" +
",PTH.EMPLOYEE_ID\n" +
",DBH.HR_DEDUCTION_AND_BENEFITS_CODE\n" +
",DBH.CHECK_DATE", startDateStr, endDateStr);
SqlDataAdapter adapter = new SqlDataAdapter(SQL, connStr);
DataTable dt = new DataTable();
adapter.Fill(dt);
jdweng
Could you elaborate more on what this code does in general?
Does it generate a table with the data between specified dates? If so, where is the table shown? 
Where does one enter in the specified start and end dates on the Web Application? Do I have to create start and end date blanks and link them to the code for it to work?
Sorry for the inconvenience - I'm just really new at this. Thanks!

Similar Messages

  • How do I create a view in SQL Server in Visual Studio Express 2013 for Desktop?

    Hi
    I've got a SQL Server database set up using the internal SQL Server in Visual Studio Express 2013 for Desktop. I want to create a view (using tables with one to many relationships) but I don't
    know how to do it.
    Where can I find a good tutorial on creating views in SQL Server in Visual Studio Express 2013 for Desktop? I think Visual Studio Express 2013 for Desktop doesn't have some view designer that
    exists in the non-express version of Visual Studio (if I'm not mistaken). So I think I'd need a tutorial on how to do the actual SQL, unless there is some tool I don't know about.
    Thanks

    Hi ,
    According to your description, if you install SQL Server SQL Server 2014 Express and SQL Server Manager Studio tools (SSMS), if you want to create a view, you can use SSMS. Then if you want to connect to and Diagram your SQL Express Database in Visual Studio
    2013, you can attach the database file by using the .NET Framework Data Provider for SQL Server in Visual Studio, and create a database diagram via expanding the “Database Diagrams” node.
     For more information, there is similar issue about how to connect to and Diagram your SQL Express Database in Visual Studio 2012 , you can review the following article,
    http://blogs.msdn.com/b/bethmassi/archive/2011/10/27/how-to-connect-to-and-diagram-your-sql-express-database-in-visual-studio-lightswitch.aspx.
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • How can i read data in pagemaker file (PMD) using Visual Studio C# NET ?

    I have bunch of data in .PMD file (Page Maker Document). Which contains mathematical equations and chemistry formulas, I am a .NET developer, and I am writing code for one of the educational learning system. For that I need to read and store mathematical equations/ chemistry formulas from .PMD file into database then display on the browser page.
    Is it possible to read data from .PMD file using C#.NET, do I need to use any external libraries. How can I import .PMD to MATHML (Mathematical Markup language)?
    Any existing examples for C#.NET?
    Please help me regarding this.

    I can't claim to know much about visual C# Net, but I do know a bit about pagemaker. It really can't handle equations. there are a few work arounds involving things like baseline shifts and multiple text boxes, but generally equations were created in different programs and placed in pagemaker in picture or eps files. Either way the chances of extracting usable data out of pagemaker is very slim.
    Jay

  • How can you change data on a SQL 2012 application database that uses availability groups from BizTalk server?

    If you use the WCF-SQL adapter it is recommend that you set UseAmbientTransaction to true if you are changing data. I think this requires MSDTC to be enabled on the SQL server that you are changing the data on. (http://msdn.microsoft.com/en-us/library/dd787981.aspx)
    I think that Availability groups does not support MSDTC. (http://msdn.microsoft.com/en-us/library/ms366279.aspx).
    How can you change data on a SQL 2012 application database that uses availability groups from BizTalk server?

    Hi,
    Yes, Availability groups doesn't support MSDTC. Please refer to the similar discusison which maybe helpfull:
    http://dba.stackexchange.com/questions/47108/alwayson-ag-dtc-with-failover
    http://stackoverflow.com/questions/17179221/msdtc-in-always-on-availability-groups

  • How to find Installation Date for each SQL installation

    Dear All,
    I need a basic info. How to find installation date of each SQL instance (My environment running with multiple standalone/cluster instances)?
    So, I need a query to find installation date easily (I don't want to check it in registry by manual). Thanks in advance...

    Hi Balmukund
    This is the same answer that (1) Prashanth posted
    from the start, letter on (2) Stan posted
    this again with the same link, and now for the third time, (3) you posted it with the same link :-)
    * This answer is correct for specific instance.
    The OP asked a solution for several instances. Therefore he should execute this on each instance. As I mentioned he can do it dynamically on all instances, for example using powershell (basic logic is, first find all instances and than post this query in a
    loop).
      Ronen Ariely
     [Personal Site]    [Blog]    [Facebook]
    Then your answer is correct :)
    Balmukund Lakhani
    Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
    This posting is provided "AS IS" with no warranties, and confers no rights.
    My Blog |
    Team Blog | @Twitter
    | Facebook
    Author: SQL Server 2012 AlwaysOn -
    Paperback, Kindle

  • I need to add a new report to the application that is done using visual studio and SSRS and SQL Server 2008

    I have an application that is done using SSRS on visual studio and it connects to the report server on SQL server 2008 environment.
    I've been changing the existing reports using visual studio 2008 and modifying the reports on the report server. How do I add a new report to the application ? I created a new report and deployed it on the report server but it didn't show up in the application.
    I can access the application source code on visual studio 2010 and TFS (Team Foundation). Thanks. 

    Hi,
    I have a question. This application retrieves SSRS reports from the report sever. When I download the reports
    from the SQL Server I can open them in visual studio 2008 but they don't open in visual studio 2010. I can access the application files on visual studio 2010 and team foundation server 2010. I was unable to open team foundation server 2008 on visual studio
    2008. The issue is that I am unable to add a report with a new name to the application. I use visual studio 2008 to deploy the reports on the report server but it has to be the same name to be able to run the report from the application. I can deploy any report
    on the report server but I can't access it from the application unless it has to be the same name as the present reports. If I keep the report the same name then it will replace the old report and the new report will run from the application. But only if it's
     the same name. I guess when I add a new report to the application with a new name I am supposed to add a definition in the application C sharp files  on visual studio 2010 so that the new report will show in the application. What's your opinion
    ? I have attached 2 images of the application and team foundation server 2010 and the report server.
    Thanks. 

  • I can not transfer date from one hard drive to another, I keep getting an error because I have two of the same file names and one file name is in caps and I cant change the file name

    can not transfer date from one hard drive to another, I keep getting an error because I have two of the same file names and one file name is in caps and I cant change the file name. My original external has an error and needs to be reformatted but I dont want to lose this informations its my entire Itunes library.

    Sounds like the source drive is formatted as case sensitive and the destination drive is not. The preferred format for OS X is case insensitive unless there is a compelling reason to go case sensitive.
    Why can't you change the filename? Is it because the source drive is having problems?  If so is this happening with only one or two or a few files? If so the best thing would be to copy those over individually and then rename them on the destination drive.
    If it is more then you can do manually and you can't change the name on the source you will have to reformat the destination as case sensitive.
    Btw this group is for discussion of the Support Communities itself, you;d do better posting to Lion group. I'll see if a host will move it.

  • Iphone has been in recovery mode for 4 hours and hasn't come back to the home screen and how can i fix this and get it back to working order?

    iphone has been in recovery mode for 4 hours and hasn't come back to the home screen and how can i fix this and get it back to working order?
    the iphone 4S has been in recovery mode for a long time and i have tried to press and hold the power and home buttons until the apple symbols comes on the screen again but it stay on the screen until the screen turns off and doesn't come back on to the home screen and have tried to sync with mac and doesn't do anything it does display the itunes and cable icons for a while but then goes back to the apple symbol and doers nothing what can I do to fix this  and not loose what is on the phone at all?

    Hi, simonRM.  
    Thank you for visiting Apple Support Communities. 
    I understand that you are unable to restore your iPhone.  Here are the best troubleshooting resources to start with when not being able to update or restore your iPhone.
    If you can't update or restore your iPhone, iPad, or iPod touch
    Resolve iOS update and restore errors in iTunes
    -Jason H.  

  • Hi, I would like to know if is it possible to install windows on mac pro , because I need to have some application like SQL server and visual studio, and they could not be install on mac

    hi, I would like to know if is it possible to install windows on macbook pro , because I need to have some application like SQL server and visual studio, and they could not be install on mac

    Windows on a Mac

  • How i can open external file in un src in Visual Studio?

    I have the version VS2012
    I try navigate in file with F12 like function definition but this not work
    <script src="~/Scripts/Inventory/Output/Create.js"></script><link href="~/Content/bootstrap.min.css" rel="stylesheet" />@{Html.RenderPartial("_Files", @Model);}
    Is there any way to do this? without having to go find the file in the file browser? (is tedious)
    if there is no way to do this I hope VS2015 already have this
    thnks in advance

    Hi ch2o,
    Based on your issue, I tried to use the F12 to find the JS or CSS file. I find that I get same result with yours, so I did some research about your issue. I find some similar thread for your issue, so I suggest you could refer it and then check your issue
    in your side.
    Reference:
    http://stackoverflow.com/questions/11776697/how-to-quickly-open-a-file-in-visual-studio-2012
    http://stackoverflow.com/questions/2667528/is-there-a-way-to-quickly-find-files-in-visual-studio-2010
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How can I upgrade from Photoshop Elements 12 to Photoshop Elements 13  AND Photoshop Premiere Elements 13? What would be the price?

    How can I upgrade from Photoshop Elements 12 to Photoshop Elements 13  AND Photoshop Premiere Elements 13? What would be the price?

    Hi Raymond,
    I would advise you to buy the bundle package of Premiere and Photoshop Elements 13 which cost 149 $ but due to online promotions the price right now is 119 $.
    Thank you for posting on Adobe Forums.

  • You know how you download apps, well let's say you have two devices and get an app on one and it goes to the other, how do you remove it from doing that?

    You know how you download apps, well let's say you have two devices and get an app on one and it goes to the other, how do you remove it from doing that?

    Click here and use the instructions to turn off the automatic downloads.
    (120206)

  • I bourgt 10.7 Lion, but i cnt´t install it. All the last updates are downloaded. I see the sign of the lion, but not clear- there stand the download stopped. How can i continue the download?

    i bourgt 10.7 Lion, but i cnt´t install it. All the last updates are downloaded. I see the sign of the lion, but not clear- there stand the download stopped. How can i continue the download?

    In that case, drag the Lion installer from your application folder to the trash. Empty trash. Now press option key and click on 'purchased' tab. The button next to the Lion installer now should say 'install' click on that to download again.

  • HT1473 I imported songs onto itunes AND my ipad but i cant get it on my ipad and that is where i really want them. how do i find and get them on my Ipad? i tried the support area but that didnt help at all.

    I imported songs onto itunes AND my ipad but i cant get it on my ipad and that is where i really want them. how do i find and get them on my Ipad? i tried the support area but that didnt help at all.

    Did you purchase them on your iPad with the same Apple ID that you are using for iTunes on your iPhone and that iTunes on your Mac is sign into?

  • How to import/export data in pl/sql developer

    how to import/export data,table script in pl/sql developer.
    By using the export functionality i am getting the dump file.I want a sql file.How do i do it?
    And i want the data in csv file and table script in a sep sql file.How do i do it?

    <li>run your query in "Query Builder"
    <li>Right-Click on the Query-Results
    <li>Click "Export"
    <li>Click on the "Drop-Down" in front of "Format" and choose "insert"
    <li>Provide the location and name of ther "sql" file.
    If you want output in CSV format, choose "csv" from the "format" drop-down.
    HTH

Maybe you are looking for

  • Adobat Pro doesn't work in CS5.5

    I should format my mac and when I installed CS5.5 it worked with my serial number. However when I would use Adobe Acrobat X pro , it asked me a new time the serial number but it didn't work. Adobe acrobat told that hte serial number couldn't be used

  • OMG SOMEBODY PLEASE HELP ME

    i am having an issue where i can not change my Adobe flash player settings. what to do???

  • Appraisals

    Hi SAP HR Gurus, My issue is about "Appraisals" in Personnel Development. I created an appraisal for an employee by navigating through the various stages of appraisal, say, "In Preparation", "In Planning", "In Review", "In Process" and "Completed" us

  • WMRUNDLL.EXE - Application Error

    WMRUNDLL.EXE - Application Error The Instruction at xxxxxxxxxx referenced memory at xxxxxxxxxx. The memory could not be read. Click on OK to terminate the program Click on CANCEL to debug the program I get this error when the login screen comes up. N

  • The input line is too long. The syntax of the command is incorrect.

    I am a prentice on J2EE by using the Tutorial 1.4. I keep getting this error message: "The input line is too long. The syntax of the command is incorrect." from the windows's terminal no matter what arguments I issued for the command asant right afte