Hot News!

Not Available

Click Like or share to support us!

Showing posts with label Problem Solution. Show all posts
Showing posts with label Problem Solution. Show all posts

Sep 14, 2015

Advanced Sql Selecting Rows With Max Value From Groups

SQL is never hard but definitely tedious. You know what I mean.
Occasionally I tend to create a relatively complicated query instead of fetching the data back and do the processing in my code. Sometimes for the performance, and sometimes just because I like challenges.
I know, I never am a SQL expert. But anyway, it might help.
Say we have a table like the following:
DepartmentEmployeeSalary
AJohn1000
AMichael1200
ABob880
BTed2000
BJane2000
CAlly2000
CKent4000
And we want to get a query of all employees having the highest pay from each department. What SQL query should we have?
Well, first we need to find what the highest pay of each department is:
SELECT 
  DEP.DEPARTMENT, MAX(DEP.SALARY) 
FROM 
  DEPARTMENT DEP 
GROUP BY 
  DEP.DEPARTMENT
This will give you a list of department with its highest pay. But we do want to fetch the complete row so that we could know who that employee is. So how do we proceed from here?
We need sub query and EXISTS predicate:
SELECT * 
FROM 
  DEPARTMENT 
WHERE 
  EXISTS (
    SELECT 
      DEP.DEPARTMENT 
    FROM 
      DEPARTMENT DEP 
    GROUP BY 
      DEP.DEPARTMENT 
    HAVING 
      DEPARTMENT.DEPARTMENT = DEP.DEPARTMENT AND 
      DEPARTMENT.SALARY = MAX(DEP.SALARY)
  )
The result looks like this:
DepartmentEmployeeSalary
AMichael1200
BTed2000
BJane2000
CKent4000
The speed of this query doesn’t seem very bad. In fact, it performs far better than I originally thought since it involves sub query.

source:https://bryantsai.com/advanced-sql-selecting-rows-with-max-value-from-groups/

Aug 27, 2015

MS SQL Server with Khmer Unicode

MS SQL Server is a product of Microsoft that we use it for store data, information and we can easy find that data when you need. MS SQL Server is the database application for manage data or any information of organization. If we compare with MS Access we can say MS SQL Server is better because MS SQL Server have more features, tools, function than MS Access in manage data.  Today I have one topic to share you about how to make MS SQL Server support with Khmer Unicode.
This is the topic that shows you about how to insert, update, delete data in Khmer to table and how to search data as Khmer language. It is the nice topic that can help who that starting build application with Khmer Unicode

1. How can we insert Khmer Unicode to table?
You need to configure something when you create table. If you want your table support with Khmer Unicode please choose datatype is nvarchar and in collation properties Khmer_100. Please create tblStudents(ID,Name,Sex) and set datatype below:


In field Name properties please set Collation to Khmer_100


2. After you create table you need to know the query that can input Khmer Unicode to table also.

             insert into tblStudents(ID,Name,Sex)
             values('1',N'សុវណ្ណ','M')

“N” character is the special string that allow input Khmer Unicode to field of table. Please run this script and see the result in table.


       3. How to Search with Khmer Unicode

           We need still use “N” when we search data in tblStudents. Please see example below:

       Select * from tblStudents
       where Name='សុវណ្ណ'

          if we write this select we will now have data.


            Then try to change to this scripts

      Select * from tblStudents
      where Name=N'សុវណ្ណ'

              Result:


You also can use “Like” to select with Khmer Unicode too.


This topic is very useful to help you to build application by using Khmer Unicode. And I hope it can help you to build application. If you have any issue please command I will to support you.

(source: http://kh-code.blogspot.com)

Jun 12, 2012

Tip: Importing Data from MS Access 2010 64-bit .accdb database into SQL Server using SSIS

Problem:
You can’t connect using Native OLEDB \Microsoft Jet 4.0 OLEDB Provider.  It fails with following error message:
Test connection failed because of an error in initializing provider. Unrecognized database format 'C:\Users\vishah\Documents\myDB.accdb'.

Solution:

image