Friday, June 02, 2023

How to get comma separated values from SQL

There are few types where you can get comma separated values form SQL SERVER using SQL

1. XML PATH method:

SELECT 
   STUFF((SELECT ', ' + column_name
          FROM table_name
          WHERE conditions
          FOR XML PATH('')), 1, 2, '') AS csv_values;
  

2. COALESCE and FOR XML method:

SELECT 
   STUFF((
      SELECT ', ' + column_name
      FROM table_name
      WHERE conditions
      FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 2, '') AS csv_values;
  

3. FOR XML PATH method

SELECT 
   STUFF((SELECT ',' + column_name
          FROM table_name
          WHERE conditions
          FOR XML PATH('')), 1, 1, '') AS csv_values;
  

In these examples, replace column_name with the actual column name and table_name with the appropriate table name. Customize the WHERE clause to filter the desired rows if necessary.

When executing these queries, a single row with a single column will be returned, containing the comma-separated values from the specified column. Please note that the XML-related methods convert the values to XML and then manipulate them, resulting in a string of comma-separated values.

Hope this helps!!

Wednesday, May 31, 2023

How to Move Offline Outlook Data File (OST) Data

To move an Offline Outlook Data File (OST) data, you can follow these steps:

  1. Close Outlook and make sure it is not running in the background.

  2. Locate the OST file on your computer. By default, it is located in the following location: Windows 10, 8, 7: C:\Users%username%\AppData\Local\Microsoft\Outlook Windows Vista: C:\Users%username%\Local Settings\Application Data\Microsoft\Outlook

  3. Copy the OST file to a new location, such as a USB drive or a different folder on your computer.

  4. Open Outlook and go to File > Account Settings > Account Settings.

  5. Select the email account that corresponds to the OST file you just moved and click Change.

  6. In the Change Account window, click More Settings.

  7. Go to the Advanced tab and click the Browse button next to the Offline Folder File Settings.

  8. Select the OST file you just moved and click OK.

  9. Click Next and Finish to complete the process.

It's important to note that when you move your OST file, you will lose any cached data, such as emails and calendar items, that have not been synced with the server.

Data Structures in Python

Python provides several built-in data structures that are commonly used in programming

Below is some helpful summary on Python Data Structures

1685466094870

Monday, May 22, 2023

Explain Generic Repository Design Pattern

A generic repository is a software design pattern commonly used in object-oriented programming to provide a generic interface for accessing data from a database or other data sources. It abstracts the underlying data access code and provides a set of common operations that can be performed on entities within a data source.

The generic repository pattern typically consists of a generic interface, such as ‘IGenericRepository’, which defines common CRUD (Create, Read, Update, Delete) operations that can be performed on entities. It also includes a generic implementation of the repository interface, such as ‘GenericRepository<T>’, which provides the concrete implementation of those operations.

Here's an example of a generic repository interface:

public interface IGenericRepository<T>
{
    T GetById(int id);
    IEnumerable<T> GetAll();
    void Add(T entity);
    void Update(T entity);
    void Delete(T entity);
}
  

And here's an example of a generic repository implementation using Entity Framework in C#:

public class GenericRepository<T> : IGenericRepository<T> where T : class
{
    private readonly DbContext _context;
    private readonly DbSet<T> _dbSet;

    public GenericRepository(DbContext context)
    {
        _context = context;
        _dbSet = context.Set<T>();
    }

    public T GetById(int id)
    {
        return _dbSet.Find(id);
    }

    public IEnumerable<T> GetAll()
    {
        return _dbSet.ToList();
    }

    public void Add(T entity)
    {
        _dbSet.Add(entity);
        _context.SaveChanges();
    }

    public void Update(T entity)
    {
        _context.Entry(entity).State = EntityState.Modified;
        _context.SaveChanges();
    }

    public void Delete(T entity)
    {
        _dbSet.Remove(entity);
        _context.SaveChanges();
    }
}
  

By using a generic repository, you can avoid writing repetitive data access code for each entity in your application and promote code reusability. However, it's worth noting that the generic repository pattern may not be suitable for every scenario and should be evaluated based on the specific requirements and complexity of your application.

Friday, May 19, 2023

SQL Server Integration not working in VS2022

Here is what you need to do, you need to install SSIS Project for VS 2022

To install Analysis Services, Integration Services, and Reporting Services project support, run the SSDT standalone installer or direct download from here.

The installer lists available Visual Studio instances to add SSDT tools. If Visual Studio isn't already installed, selecting Install a new SQL Server Data Tools instance installs SSDT with a minimal version of Visual Studio, but for the best experience, we recommend using SSDT with the latest version of Visual Studio