I have a sql 2005 dev ed running an application developed in vs.net 2005 C# I have several gridviews which have a field call first name and a field called lastname I need to put both the firstname and lastname in the same cell or colum row. I do not now how to join these. Can some one help me with a SQL query string that will do this for me.You could do SELECT FirstName + ' ' + LastName FROM YourTable|||SELECT FirstName + ' ' + LastName AS FullName
FROM Employees
Showing posts with label joining. Show all posts
Showing posts with label joining. Show all posts
Monday, March 19, 2012
Monday, March 12, 2012
Newbie help On Sql string form vb
HI, I just started db programming for this project I am working on. I am having a problem joining two tables where both of their "EmployeeID" fields is equal to my Vb EmpID string...
I was trying the code:
SqlQuery = "SELECT TblEmpAttendance.Date, TblEmpAttendance.Value," & _
"TblEmployees.TotalPoints, TblEmployees.DaysWorked FROM TblEmployees RIGHT JOIN TblEmpAttendance ON TblEmployees.EmployeeID WHERE TblEmpAttendance.EmployeeID" & _
"= TblEmpAttendance.EmployeeID AND TblAttendance.EmployeeID=" & EmpID
Any help would be appreciated.
Thanks
-Greg S.Oops I already posted it but ill dbl chk anyhow. I got it to work using:
SqlQuery = "SELECT TblEmpAttendance.EmployeeID, TblEmpAttendance.Date, TblEmpAttendance.Value," & _
"TblEmployees.TotalPoints, TblEmployees.DaysWorked FROM TblEmployees RIGHT JOIN TblEmpAttendance ON TblEmployees.EmployeeID = TblEmpAttendance.EmployeeID WHERE TblEmployees.EmployeeID = " & EmpID
Is their anyhting that could cause problems with this statement?
Thanks
-Greg S
I was trying the code:
SqlQuery = "SELECT TblEmpAttendance.Date, TblEmpAttendance.Value," & _
"TblEmployees.TotalPoints, TblEmployees.DaysWorked FROM TblEmployees RIGHT JOIN TblEmpAttendance ON TblEmployees.EmployeeID WHERE TblEmpAttendance.EmployeeID" & _
"= TblEmpAttendance.EmployeeID AND TblAttendance.EmployeeID=" & EmpID
Any help would be appreciated.
Thanks
-Greg S.Oops I already posted it but ill dbl chk anyhow. I got it to work using:
SqlQuery = "SELECT TblEmpAttendance.EmployeeID, TblEmpAttendance.Date, TblEmpAttendance.Value," & _
"TblEmployees.TotalPoints, TblEmployees.DaysWorked FROM TblEmployees RIGHT JOIN TblEmpAttendance ON TblEmployees.EmployeeID = TblEmpAttendance.EmployeeID WHERE TblEmployees.EmployeeID = " & EmpID
Is their anyhting that could cause problems with this statement?
Thanks
-Greg S
Wednesday, March 7, 2012
Newbie : Need Help in joining Multiple tables
I am using a query to get data about temp job & temp rates for an employee database. Problem is this query pulls up two records with different rates for the same work period. THE JOB_RATE table has two different job rates with different JOBRATE_EFFECTIVE_RATE . What candition should I add in this query so that it pulls up the Jobrate applicable to that particular WORKDATE & not all JOBRATES .
i.e,
say if Jobrate = 10 on 1-Dec-2002 & later revised to Jobrate =20 effective 1-Jan-2003, then for a particular workdate 16-Dec-02 ,
the report should display one record with Temp_rate= 10 instadof two records with diffenrent rates, other data being same
select EMPLOYEE.EMP_ID,
Job.Job_name Temp_job,
Job_Rate.Jobrate_Rate Temp_Rate,
To_Char(Work_Detail.Wrkd_Work_Date,'MM-DD-YYYY') WorkDate ,
To_Char(Work_Detail.wrkd_Start_Time,'HH24:MI') BeginTime ,
To_Char(Work_Detail.wrkd_End_time,'HH24:MI') EndTime
from Employee , Job, Job_Rate ,Work_Detail,Work_Summary
where EMPLOYEE.EMP_ID = WORK_SUMMARY.EMP_ID
AND WORK_SUMMARY.WRKS_ID = WORK_DETAIL.WRKS_ID
AND WORK_DETAIL.JOB_ID = JOB.JOB_ID
AND JOB.JOB_ID = Job_Rate.Job_IdOriginally posted by ritz1975
I am using a query to get data about temp job & temp rates for an employee database. Problem is this query pulls up two records with different rates for the same work period. THE JOB_RATE table has two different job rates with different JOBRATE_EFFECTIVE_RATE . What candition should I add in this query so that it pulls up the Jobrate applicable to that particular WORKDATE & not all JOBRATES .
i.e,
say if Jobrate = 10 on 1-Dec-2002 & later revised to Jobrate =20 effective 1-Jan-2003, then for a particular workdate 16-Dec-02 ,
the report should display one record with Temp_rate= 10 instadof two records with diffenrent rates, other data being same
select EMPLOYEE.EMP_ID,
Job.Job_name Temp_job,
Job_Rate.Jobrate_Rate Temp_Rate,
To_Char(Work_Detail.Wrkd_Work_Date,'MM-DD-YYYY') WorkDate ,
To_Char(Work_Detail.wrkd_Start_Time,'HH24:MI') BeginTime ,
To_Char(Work_Detail.wrkd_End_time,'HH24:MI') EndTime
from Employee , Job, Job_Rate ,Work_Detail,Work_Summary
where EMPLOYEE.EMP_ID = WORK_SUMMARY.EMP_ID
AND WORK_SUMMARY.WRKS_ID = WORK_DETAIL.WRKS_ID
AND WORK_DETAIL.JOB_ID = JOB.JOB_ID
AND JOB.JOB_ID = Job_Rate.Job_Id
You need to say:
AND job_rate.effective_date =
( SELECT MAX(jr.effective_date)
FROM job_rate jr
WHERE jr.effective_date <= Work_Detail.Wrkd_Work_Date
AND jr.job_id = job.job_id)
It is common to have a job_rate.end_date column to overcome this, so that the condition is simply:
AND Work_Detail.Wrkd_Work_Date BETWEEN job_rate.effective_date AND job_rate.end_date
This simplifies the query, but adds complication to the rate maintenance functionality.|||Thanks Andrewst .
The query has worked & I am satisfied after testing it .Thanks a lot for the help.
i.e,
say if Jobrate = 10 on 1-Dec-2002 & later revised to Jobrate =20 effective 1-Jan-2003, then for a particular workdate 16-Dec-02 ,
the report should display one record with Temp_rate= 10 instadof two records with diffenrent rates, other data being same
select EMPLOYEE.EMP_ID,
Job.Job_name Temp_job,
Job_Rate.Jobrate_Rate Temp_Rate,
To_Char(Work_Detail.Wrkd_Work_Date,'MM-DD-YYYY') WorkDate ,
To_Char(Work_Detail.wrkd_Start_Time,'HH24:MI') BeginTime ,
To_Char(Work_Detail.wrkd_End_time,'HH24:MI') EndTime
from Employee , Job, Job_Rate ,Work_Detail,Work_Summary
where EMPLOYEE.EMP_ID = WORK_SUMMARY.EMP_ID
AND WORK_SUMMARY.WRKS_ID = WORK_DETAIL.WRKS_ID
AND WORK_DETAIL.JOB_ID = JOB.JOB_ID
AND JOB.JOB_ID = Job_Rate.Job_IdOriginally posted by ritz1975
I am using a query to get data about temp job & temp rates for an employee database. Problem is this query pulls up two records with different rates for the same work period. THE JOB_RATE table has two different job rates with different JOBRATE_EFFECTIVE_RATE . What candition should I add in this query so that it pulls up the Jobrate applicable to that particular WORKDATE & not all JOBRATES .
i.e,
say if Jobrate = 10 on 1-Dec-2002 & later revised to Jobrate =20 effective 1-Jan-2003, then for a particular workdate 16-Dec-02 ,
the report should display one record with Temp_rate= 10 instadof two records with diffenrent rates, other data being same
select EMPLOYEE.EMP_ID,
Job.Job_name Temp_job,
Job_Rate.Jobrate_Rate Temp_Rate,
To_Char(Work_Detail.Wrkd_Work_Date,'MM-DD-YYYY') WorkDate ,
To_Char(Work_Detail.wrkd_Start_Time,'HH24:MI') BeginTime ,
To_Char(Work_Detail.wrkd_End_time,'HH24:MI') EndTime
from Employee , Job, Job_Rate ,Work_Detail,Work_Summary
where EMPLOYEE.EMP_ID = WORK_SUMMARY.EMP_ID
AND WORK_SUMMARY.WRKS_ID = WORK_DETAIL.WRKS_ID
AND WORK_DETAIL.JOB_ID = JOB.JOB_ID
AND JOB.JOB_ID = Job_Rate.Job_Id
You need to say:
AND job_rate.effective_date =
( SELECT MAX(jr.effective_date)
FROM job_rate jr
WHERE jr.effective_date <= Work_Detail.Wrkd_Work_Date
AND jr.job_id = job.job_id)
It is common to have a job_rate.end_date column to overcome this, so that the condition is simply:
AND Work_Detail.Wrkd_Work_Date BETWEEN job_rate.effective_date AND job_rate.end_date
This simplifies the query, but adds complication to the rate maintenance functionality.|||Thanks Andrewst .
The query has worked & I am satisfied after testing it .Thanks a lot for the help.
Subscribe to:
Posts (Atom)