Posts

Showing posts from 2020

Creating Stored Procedure in Mysql

 I hope this will be helpful for the beginners who are just starting their career with mysql . DELIMITER $$ CREATE PROCEDURE usp_logout ( IN iInputType INT ) BEGIN IF (iInputType=1) THEN SELECT * FROM TEST1; ELSEIF (iInputType=2) THEN                 SELECT * FROM TEST2;     ELSE SELECT FALSE; END IF;      END$$

Some SQL facts

1. An aggregate function does not accept sub query as an input. Example Having sum (select ...)>5 2. Processing order for 'ON' and 'WHERE'           a)ON            b)WHERE 3.'Distinct' and 'Order by ' can't be used in the same query. 4. Table is organised in one of these ways (Heap ,B-tree).Table organization is called "HOBT" 5. Extent has 8 pages. Each page has 8kb.

What are the query filters in SQL?

1. ON 2. WHERE 3. HAVING  The above 3 keywords are considered as query filters in SQL.

SQL logical query processing order

It's very important to know that how SQL query is processed inside whenever we execute it.  1. FROM - Left to Right 2. WHERE 3. GROUP BY 4. HAVING 5. SELECT 6. ORDER BY 7.  OFFSET/FETCH 

Cannot resolve collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AS" error

These kind of errors are often thrown in sql. Today i am going to tell you ,how to resolve this error. At first we should identify which column creates this issue. Next we have to add " COLLATE DATABASE_DEFAULT " this keyword next to the column. Now you won't have this error. Example: select e.employeeName COLLATE DATABASE_DEFAULT from employee

Comma separated strings to distinct list conversion in C#

Today we are going to see that how to convert comma separated string to list conversion . I hope we may come across this kind to situation. So it will be more helpful . string commaSeparatedString ="1,2,3,4,5,,6"; List<string> lstDistinctString = new List<string>(); lstDistinctString = commaSeparatedString. Trim().Split(',').Where(s =>           !string.IsNullOrWhiteSpace(s)).Distinct().ToList() ; Output: 1 2 3 4 5 6

Sql performance tuning

* Use with(no lock ) for every table  while selecting records in Stored procedures ,views and functions . * Use limit if you have more records. * Create index on a table as per our requirements.

"All" and "Any" keywords in SQL

Today we are going to learn two useful keywords from SQL . 1.ALL It's equivalent to AND  condition. SELECT * FROM EMPLOYEE WHERE AGE > ALL (25,30,35) 2.ANY   It's equivalent to OR  condition. SELECT * FROM EMPLOYEE WHERE AGE > ANY(25,30,35)

Splitting comma separated values into row values in SQL

Today we are going to see how to separate the comma separated values in sql. We are often come across these kind of situation to split strings with comma. So i hope this would be more helpful. --Declaration                                                                                  DECLARE @xml XML,@commaValues NVARCHAR(2000)         --Initialization SET @xml = N'<t>' + REPLACE(@commaValues ,',','</t><t>') + '</t>'    --Temporary table creation      CREATE TABLE #tmp(studentid int)        --Inserting values  in temporary table INSERT INTO #tmp          SELECT r.value('.','Nvarchar(MAX)') as item          FROM @xml.node...

Stored Procedure with Try Catch in SQL

-- =============================================          -- Author:  <SARAVANANS>          -- Create date: <22-NOV-14>          -- Description: <Common sp to update employee details>          -- [usp_update_employee] 1        -- =============================================          CREATE PROCEDURE [dbo].[usp_update_employee]             @EmployeeID INT ,  @EmployeeSalary MONEY AS          BEGIN TRY                  SET ARITHABORT  ON        SET NOCOUNT ON    UPDATE EMPLOYEE SET EMPLOYEESALARY =@EmployeeSalary WHERE EmployeeID =@EmployeeID  END TRY          BEGIN CATCH            SELECT @ErrorNumbe...

Create PDF from TIFF using iTextSharp in C#

        private void ConvertTIFFtoPDF(string tiffFileName,  PdfWriter writer,  Document document)         {             try             {                 using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(tiffFileName))                 {                     int numberOfPages = bitmap.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);                     PdfContentByte cb = writer.DirectContent;                     for (int page = 0; page < numberOfPages; page++)                     {                         bi...

How to check whether the website is active or not using c#?

HttpClient client = new HttpClient (); var response = await client . GetAsync ( url ); if (r esponse . IsSuccessStatusCode ) { return "Active" ; } else { return "InActive" ; }

Creating web api call using C#

public class WebapiClient  { private static string _apiBaseUrl=Configuration Manager.AppSettings["Apiurl"]; private static double _apiTimeout=Convert.ToDouble(Configuration Manager.AppSettings["ApiTimeout"]); public static HttpClient CreateHttpClient() { HttpClient client= new HttpClient(); client.BaseAddress=new Uri(_apiBaseUrl); client.Timeout=TimeSpan.FromMinutes(_A pi time out); return client; } } public class ApicallTest { public bool MakeApiCall() { try { var apiClient= WebApiClient.CreateHttpClient(); HttpResponseMessage response= apiClient.PostAsJsonAsync(apiname, input).Result; if(response.StatusCode) { var jsonContent= response.Content.ReadAsStringAsync().Result; var result= JsonConvert.DeserializeObject<book>(jsonContent); return result; } else { return false; } } catch() { return false; } finally { apiClient.Dispose (); } } }