Posts

Showing posts from February, 2024

SQL SERVER Try Convert

Image
SQL SERVER Try Convert Select TRY_CONVERT(int,123456) , TRY_CONVERT(int,'Char to NUmber')  , TRY_CONVERT(int,'00000111')  , TRY_CONVERT(int,'1234ACEF')   Instead of throwing error it will return Null Select TRY_CONVERT(Date,'12/24/2015'),  TRY_CONVERT(Date,'12242015')  Instead of throwing error it will return Null

SQL Server Concat Feature

Image
SQL Server  Concat  Feature Concat  - feature allow to merge two string values. If value which are getting concat has null inside the same. All other content of that part will not get concat into string.  This Good Feature when it come to  Concatation of String Value Specify Address When certain Part of value is not there it still shows Comma Select Concat('Switin ' ,  ',' +  'G'  +   ','  , ' Kotian'), Concat('Switin ' ,  ', ' +  NULL  +   ', '  , 'Kotian')      In Case of NULL The Comma is not appearing. 

SQL SERVER - Alter with Default Values

SQL SERVER  -  Alter with Default Values -- Alter Table to add Field with Default Value for Existing Records -- Which is not possible with Multiple Alter add Statement for Column and Constrainst Alter TABLE [dbo].[Table_1] ADD [UUUX] [bit] NOT NULL  CONSTRAINT [DF_Table_1_UUUX]  DEFAULT 0   Alter TABLE [dbo].[Table_1] ADD [YUYUY1234] [int] NOT NULL  CONSTRAINT  [YUYUY1234] DEFAULT ((0) )   

SQL SERVER - Check for Carriage Return or Enter and Replace with Space

SQL SERVER  -   Check for Carriage Return or Enter Select  Charindex(CHAR(13)+char(10),Address,1) , REPLACE(Address,CHAR(13)+char(10),'') from mastShipToParty

SQL Server - Generate a script for fields which are part of each table in database

  SQL Server - Generate a script for fields which are part of each table in database When you need to some fixed fields to be part of each header table in database and always we have to create those field manually by type field name and creating foreign key. We can do this with help of below script. which I found helpful each time in create new table in database. In my case I had AddOprID , and EditOprID to part of each table and same is foreign key reference to User Master.   Declare @UserTable as Varchar(100) Declare @Schema as Varchar(100) Declare @Table as Varchar(100) Declare @SQL as varchar(8000)     SET @UserTable ='mastUser' SET @Schema ='dbo' SET @Table ='TranSales'     SET @SQL   = 'Alter TABLE [' + @Schema +'].[' + @Table + '] ADD [AddOprID] [int] NOT NULL   ' + Convert(Varchar,CHAR(10)) +                         ...

SQL SERVER - BEGIN TRANSCATION AND ROLLBACK

            SQL SERVER - BEGIN TRANSCATION AND ROLLBACK  USE [tempdb] GO /****** Object:  Table [dbo].[Table_1]    Script Date: 02/06/16 18:05:30 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Table_1]( [fld1] [int] NULL, [fld2] [int] NULL ) ON [PRIMARY] GO Insert into Table_1 (fld1,fld2) Values (0,100) begin Select * from Table_1 End  -- This will Terminat T-sql and rollback same if error occurs begin Try begin tran Delete from Table_1 Where fld1 = 0 Insert into Table_1 (fld1,fld2) Values ('Switin',0) COMMIT Tran End Try begin Catch SELECT ERROR_MESSAGE() AS ErrorMessage;   ROLLBACK TRAN  End Catch -- Begin End will not stop execution of next T-sql . Its Just logic Grouping of T-SQL begin Delete from Table_1 Where fld1 = 0 Insert into Table_1 (fld1,fld2) Values ('Switin',0) Select * from Table_1 End 

Syncfusion Multicolumn Combobox - adding Data in Design Time in Combobox

Image
Syncfusion Multicolumn Combobox - adding Data in Design Time in Combobox Have data in multicolumn combo box in Design Time. Custom Data Item Window to add data in combo box   Custom property which will help to add data in combobox       Step 1 – Create Inherited Custom Control using Syncfusion Multicolumn Combo box         Step 2 – Custom Class to hold Data item Public Class ComboItem     Dim strText As String     Dim strValue As String       Public Property Text() As String         Get             Return strText         End Get         Set(ByVal value As String)             strText = value         End Set     End Property     ...