Eg Net Solution: sql

Here in this sites web and software developer can get some essential information.

MY Favorite .Net Question For Interview

This are not tidy. Just for rough. In Sha Allah will make it tiddy soon. 1.  DateTime2 Date range 0001-01-01 through 9999-12-31  vs Date...

Users Countries


Showing posts with label sql. Show all posts
Showing posts with label sql. Show all posts

Thursday, December 27, 2018

SQL TRICKS

December 27, 2018 0
SQL TRICKS
1. Student Table have:ID, STUDENT_ID, STUDENT_NAME, YEAR, CLASS, ROLL
Find each student  name, the last year in database, class  name

  1. ID, STUDENT_ID    STUDENT_NAME  YEAR   CLASS   ROLL
  2. 1          2                           A                           2010       I             5
  3. 2          2                           A                           2012      III           5
  4. 3          5                          C                           2010      IX           5
  5. 4          2                           A                           2014      V             5
  6. 5          7                           E                           2018      IX           5
  7. 6          2                           A                           2016      VII          5
   Query: 
  1.      Select ST1.ID, ST1.STUDENT_ID, ST1.STUDENT_NAME, ST1.YEAR, ST1.CLASS, ROLL from STUDENT ST1 INNER JOIN
  2.   (
  3.      SELECT  STUDENT_ID ,  MAX(YEAR)  MAXYEAR from STUDENT GROUP BY  STUDENT_ID    
  4.    )
  5.    ST2 on ST1.STUDENT_ID     = ST2.STUDENT_ID    AND ST1.ID = ST2.ID

Monday, December 24, 2018

RDLC Report Definition Language Client Site Snippet

December 24, 2018 0
RDLC Report Definition Language Client Site Snippet
1. FormatDateTime to required Format

  1. =FormatDateTime(Fields!OrderDate.Value, DateFormat.ShortDate)
  2. =Format(now( ),"dd-MMM-yyyy HH:mm:ss tt")
  3. =Format( Fields!CreateDate.Value, "dd-MMM-yyyy")
  4. =FormatNumber(Sum(Fields!FinishQty.Value),0)
  5. =FormatDateTime(Fields!DeliveryDate.Value, DateFormat.ShortDate) 

        For Printing Serial In RDLC
  1. =RowNumber(Nothing)
     If Condition in RDLC
     =IIf(Parameters!UnitListId.Value = "6", "Color City Ltd.",                       
            IIf(Parameters!UnitListId.Value = "1", "Mymun Textile Ltd.", 
                 IIf(Parameters!UnitListId.Value = "2", "Hamza  Textile Ltd",
                       "Mymun Complex")))
    Switch case in RDLC
        = Switch( Fields!FlagGroup.Value =  0, "00-60 days",
          Fields!FlagGroup.Value =  1, "61-120 Days",
          Fields!FlagGroup.Value =  2, "121-180 Days",
          Fields!FlagGroup.Value =  3, "181-270 Days",
          Fields!FlagGroup.Value =  4, "271-365 Days",
          Fields!FlagGroup.Value = 5,  "More than 365 Days" ,

  1 = 1,                          "default value" )
   Formatting number to Desired Decimal Points:
    =FormatNumber(Sum(Fields!FinishQty.Value), 0)

  Iff condition in Function: 
   =FormatNumber( Sum(IIf(Fields!FlagColumn = 0, Fields!FinishQty.Value ,0 )    ),0)
   =IIf(Fields!FlagColumn = 0, FormatNumber( Sum(Fields!FinishQty), 0),0 )



Thursday, November 1, 2018

Using SqlClient connect to sql server and CRUD in Databse thorough Stored Procedure

November 01, 2018 0
Using SqlClient  connect to sql server and CRUD in Databse thorough Stored Procedure

  1.   public List<LDNo> LDNoList(Int64? LDNo)
  2.         {

  3.             ResultModel result = new Models.ViewModel.CommonViewModel.ResultModel();
  4.             string error = String.Empty;
  5.             QUERY2 query = new QUERY2();
  6.             Dictionary<string, object> dict = new Dictionary<string, object>();//= new Dictionary<string, string> 
  7.             List<LDNo> ldnoList = new List<LDNo>();

  8.             dict.Add("@LDNO", LDNo);
  9.             dict.Add("@Result", 1.ToString());
  10.             dict.Add("@Message", "Message".ToString());
  11.             query.SQL = @"SPROC_GET_tblDyesForecastingHead_LDNO";
  12.             query.PARAMETER = dict;
  13.             clsDataprocess cls = new clsDataprocess();
  14.             result = cls.ExecuteSqlStoredProcedureSaveEdit(query, "get", out error);
  15.             if (result.Result && result.DtTable != null && result.DtTable.Rows.Count > 0)
  16.             {
  17.                 Int64 tempi = 0;
  18.                 for (int i = 0; i < result.DtTable.Rows.Count; i++)
  19.                 {
  20.                     LDNo lDNo = new LDNo();
  21.                     Int64.TryParse(result.DtTable.Rows[i]["LDNO"].ToString(), out tempi);
  22.                     lDNo.LdNo = tempi;
  23.                     ldnoList.Add(lDNo);

  24.                 }
  25.                 string Message = result.Message;
  26.                 string Result = result.Result.ToString();
  27.             }
  28.             else if (!result.Result)
  29.             {
  30.                 throw new Exception(result.Message);
  31.             }

  32.             return ldnoList;
  33.         }

Tuesday, October 9, 2018

SQL Snippet

October 09, 2018 0
SQL Snippet

Select multiple columns from a subquery in Select Statement with SQL Server Or Use OF Outer Apply

  1. SELECT t1.ID, t1.fck, t1.f1, t3.f2, t3.f3
  2. FROM tbl1 AS t1
  3. OUTER APPLY (
  4. SELECT f2, f3 
  5. FROM tbl2 AS t2 
  6. WHERE t2.ID = t1.fck) AS t3



Decaaring table as Variable And Inserting In it:

  1. declare @listOfTablesArrangementIDs table (id int);  
  2. insert @listOfTablesArrangementIDs(id) values(1),(2),(3) 
  3. insert @listOfTablesArrangementIDs(id) values(2027),(20258),(7)  
  4. select  * from TablesArrangement where ID NOT IN (select * from @listOfTablesArrangementIDs ) AND AreaCode = 'tst1'



Create Trigger

  1.  -- ============================================= 
  2.  -- Author: <Muhammad Ashikuzzaman,,Name> 
  3.  -- Create date: <24-10-2018,,> 
  4.  -- Edit date: <14-08-2018, > 
  5.  -- Description: <Initial server: 192.168.153.208 > 
  6.  -- ============================================= 
  7.  CREATE TRIGGER [ccl2].[TRG_TBL_PriceSetup] 
  8.  ON [ccl2].[TBL_PriceSetup] 
  9.  AFTER UPDATE 
  10.  AS 
  11.  BEGIN 
  12.  -- SET NOCOUNT ON added to prevent extra result sets from 
  13.  -- interfering with SELECT statements. 
  14.  SET NOCOUNT ON; 
  15.  --Declare @PriceID bigint 
  16.  --Select @PriceID = PriceID From deleted 
  17.  
  18.  insert into ccl2.ARC_PriceSetup (PriceID,Price) 
  19.  select PriceID,Price from deleted 
  20.  END
Create A Stored Procedure


  1. USE [ProjectInfoDB]
  2. GO
  3. /****** Object:  StoredProcedure [dbo].[SPROC_GET_tblDyesForecastingHead_LDNO]    Script Date: 11/1/2018 12:44:51 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. -- =============================================
  9. -- Author: <Muhammad Ashikuzzaman,,Name>
  10. -- Create date: <14-08-2018,,>
  11. -- Edit date: < ,,>
  12. -- Description: <Initial server: 192.168.153.208 ,,>
  13. -- =============================================
  14.  ALTER PROCEDURE [dbo].[SPROC_GET_tblDyesForecastingHead_LDNO] 
  15.  @LDNO bigint = null, 
  16.  @Result  bit =1 out ,
  17.  @Message  nvarchar(200) = 'ok' out   
  18.   
  19.  AS
  20. BEGIN
  21.   
  22. SET NOCOUNT ON;

  23. --select top 50  CommonId_For_ForeCastingDetails, DyeingPart, DyesID  from dbo.tblDyesForecastingDetail

  24.  select DISTINCT  LDNO  from dbo.tblDyesForecastingHead 
  25.  where   Convert(nvarchar(50), LDNO) like '%'+ Convert(nvarchar(50), ISNULL(@LDNO, LDNO) ) +'%'

  26.  --select top 50  CommonId_For_ForeCastingDetails, DyeingPart, DyesID  from dbo.tblDyesForecastingDetail

  27.  If (@@ERROR<>0)
  28. Begin
  29. set @Result = 0
  30. set @Message = 'Failed to Retrieve, Try Again'
  31. End
  32. Else
  33. BEGIN
  34.      set @Result = 1
  35.      set @Message = 'Data was Retrieved successfully'
  36. END
  37. END
Create a Cursor and traverse selected row through this cursor

  1. declare @Test table (Id int, Col1 int, Col2 int, Col3 int)
  2. insert into @Test (Id , Col1 , Col2 , Col3 )
  3. values  (1 , 1 , 1 , 40 ),
  4.             (2 , 1 , 1 , 41 ), 
  5.             (3 , 1 , 1 , 41 ),
  6.             (4 , 1 , 1 , 42 ),
  7.             (5 , 1 , 2 , 40 ),
  8.             (6 , 1 , 3 , 41 )
  9.  
  10.           declare @Id bigint
  11.           declare @col1 int 
  12.            declare @col2 int 
  13.            declare @col3 int  
  14.            declare @CtnInfo cursor  
  15.            set @CtnInfo = CURSOR FOR  
  16.            SELECT Id, COL1, COL2, COL3 FROM @Test  
  17.            declare @tblBody nvarchar(max) 
  18.            set @tblBody= 'Start : '  
  19.            OPEN @CtnInfo  
  20.            SELECT @@FETCH_STATUS as FETCH_STATUS1 
  21.            WHILE 1 = 1 
  22.            BEGIN  
  23.            FETCH NEXT FROM @CtnInfo INTO
  24.                                                      @id, @col1, @col2, @col3 

  25.            IF @@FETCH_STATUS = -1 
  26.            Break 
  27.            Else  
  28.            SET @tblBody=@tblBody+ ', ' + convert(nvarchar(20), @Id) 
  29.            END  
  30.            CLOSE @CtnInfo 
  31.            DEALLOCATE @CtnInfo  
  32.            SELECT @@FETCH_STATUS as FETCH_STATUS2 
  33.            select @tblBody as TotalSelecteddata
   


Understanding partition by 
  1. -- My understanding partition by will count seqs increasingly until partition  by column value remain unchanged
  2.     declare @Test table (id int, Col1 int, Col2 int, Col3 int)
  3.     insert into @Test (id , Col1 , Col2 , Col3 )
  4.     values (1 , 1 , 1 , 40 ),
  5.     (1 , 1 , 1 , 41 ),
  6.     (1 , 1 , 1 , 41 ),
  7.     (1 , 1 , 1 , 42 ),
  8.     (1 , 1 , 2 , 40 ),
  9.     (1 , 1 , 3 , 41 ),
  10.     (1 , 1 , 3 , 41 ),
  11.     (2 , 1 , 4 , 43 ),
  12.     (2 , 2 , 1 , 43 ),
  13.     (2 , 2 , 1 , 44 ),
  14.     (2 , 2 , 2 , 44 ),
  15.     (2 , 2 , 3 , 44 ),
  16.     (2 , 2 , 4 , 45 ),
  17.     (3 , 3 , 1 , 46 ),
  18.     (4 , 3 , 2 , 46 ),
  19.     (5 , 3 , 2 , 47 )
  20. -- Normal Group BY
  21.     select col1, col2 , count(Col1) Col1Count, count(Col2) Col2Count
  22.     from @Test
  23.     group by col1, col2 order by Col1

  24. --partition BY With Group BY
  25. -- My understanding partition by will count seqs increasingly untill partition by column value remain unchanged
  26.     select col1, col2, col3, count(col3)Col3Count, row_number()
  27.     over (Partition BY col1 , col2
  28.     order By col1 ) seqs
  29.     from @Test
  30.     group by col1, col2, col3
  31.     order by col1, col2





Remove Time portion from a date time
select DATEADD(DD, DATEDIFF(dd, 0, '2018-12-25 12:25:00'  ), 0)-- will remove time  portion from the date

 select DATEDIFF(dd, 0, '2018-12-25 12:25:00'  )  here 2nd parameter   0 means  '1900-01-01'


Send Mail By sp_send_dbmail stored procedure

  1.            declare @tblBody nvarchar(max) 
  2.            set @tblBody='<style type="text/css"> 
  3.    #detail_table {
  4.            border: 2px solid gray; 
  5.                border-collapse: collapse; 
  6.                          }      
  7.   #one td {          border: 1px solid #00000;       }  
  8.   #detail_table td , #detail_table th {
  9. text-align: center;
  10. border: 1px solid gray; 
  11. } </style>'
  12.           set @tblBody=@tblBody+'<div align="center" style=" border:0px solid #000000; width: 98%;height: 95%;padding: 8px;padding-top:0px; margin: 5px;">  <div align="center"  style="font-weight: bold;font-size: 22px;"> HamdoonSoft Complex </div>  <div style="clear:both;padding: 7px;"></div>   <div align="center" style="font-weight: bold;font-size: 16px; width:230px; border-bottom: 1px solid #222;position:absolute; left:42%">  Hamdoon Soft Notification </div>  <div style="clear:both;"></div>  
  13. <div align="left" style="font-size:12px;border:0px solid #000000; width: 99%;height: 100%;padding: 20px;padding-top:0px;">  
  14.    <div align="left" style="margin-top:35px;"><b> Date: </b> '+  convert( nvarchar(30) , GETDATE() )+'</div>  
  15. <div align="left" style="margin-top:8px;">To, </div>  
  16. <div align="left" style="margin-top:10px; margin-left:20px;">DGM/ AGM/ Sr. Manager</div>  <div align="left" style="margin-top:5px; margin-left:20px; height: 30px; "> Department: '+ '@ResponsibleDepartment' +'</div>  <div align="left" style="margin-top:5px; margin-left:22px;">Subject: Problematic fabric information from off line Inspection  to problamatic department.</div>  <div align="left" style="margin-top:18px;">Dear Sir</div>   <div align="left" style="margin-top:15px; margin-left:20px;">This is to inform you that, we found below batch problematic during 100% inspection in off line quality zone.</div> 
  17.     <div align="left" style="margin-top:8px;">Details :- </div>  
  18.           <br/>       <table id="detail_table" style="margin-top:20px; margin-right:.5%; width:99.5%;  "   >     <tr id="one">  <th>C1 </th> <th>C2 </th> <th>C3 </th> <th>C4 </th> <th>C5</th>    </tr>   '
  19.             
  20. DECLARE @c1        NVARCHAR(40)
  21. DECLARE @c2   NVARCHAR(40)
  22. DECLARE @c3   NVARCHAR(40)
  23. DECLARE @c4   NVARCHAR(40)
  24. DECLARE @c5   NVARCHAR(40) 
  25.          
  26.    declare @CtnInfo cursor  
  27.            set @CtnInfo = CURSOR FOR  
  28.             
  29.   SELECT    * from (values    (1, 2, 3, 4, 5)  , (1, 2, 3, 4, 5) ) 
  30.                 t21 (c1, c2, c3, c4, c5)

  31.            OPEN @CtnInfo   
  32.            WHILE 1 = 1 
  33.            BEGIN  
  34.            FETCH NEXT FROM @CtnInfo INTO
  35.               @c1, @c2, @c3, @c4, @c5 
  36.    IF @@FETCH_STATUS = -1 
  37.                Break 
  38.            Else  
  39.           set @tblBody=@tblBody+' <tr > 
  40.            <td  align="center" > '+@c1+'  </td>   <td  align="center" > '+@c2 +'  </td>   <td align="center" > '+@c3 +'  </td>   <td align="center" > '+@c4+' </td><td align="center" > '+@c5+'</td> </tr>   '
  41.            END  
  42.            CLOSE @CtnInfo 
  43.            DEALLOCATE @CtnInfo  
  44.            SELECT @@FETCH_STATUS as FETCH_STATUS2 
  45.            select @tblBody as TotalSelecteddata
  46.    set @tblBody=@tblBody+' </table> <br/> <div style="position: relative!important;left: -530px!important; top: 10px!important; font-weight:bold;  font-family:Verdana, Arial, Helvetica, sans-serif;"> </div>  </div>  </div>'
  47.            Set @tblBody=@tblBody+'<div style="Font-weight:bold; margin-top:30px;font-family:Verdana, Arial, Helvetica, sans-serif; "> Best Regards </div>  <div style=" Font-weight:bold; margin-top:10px;font-family:Verdana, Arial, Helvetica, sans-serif; "> MIS Department </div>'
  48.  
  49. declare @recipient nvarchar(max) = 'ashikcse20@gmail.com;'
  50. declare @copy_recipient nvarchar(max) = ' ashikcse20@gmail.com;'
  51.  
  52. EXEC msdb.dbo.sp_send_dbmail 
  53.  
  54. @profile_name = 'MIS-MTL',  
  55. @recipients =  @recipient, 
  56. @copy_recipients= @copy_recipient ,  
  57. @body =   @tblBody  ,
  58. @subject = 'Automatic Mail Sending',
  59. @body_format = 'HTML' 


Wednesday, August 15, 2018

Using SqlClient connect to sql server and CRUD in Databse thorough code base Inner Query Query

August 15, 2018 0
Using SqlClient  connect to sql server and CRUD in Databse thorough code base Inner Query Query
2.  SqlClientCode For Calling StoredProcedure for Getting Data

  1.   public JsonResult BuyerList()
  2.         {
  3.             Chemical_DAL obj_dal = new Chemical_DAL();
  4.             return Json(obj_dal.BuyerList());
  5.         }

2. Service
  1. public class QUERY
  2. {
  3.     public string SQL { get; set; }
  4.     public Dictionary<string, string> PARAMETER { get; set; }
  5.     public Dictionary<string, byte[]> BYTEPARAMETER { get; set; }
  6. }



Wednesday, July 11, 2018

MY Favorite .Net Question For Interview

July 11, 2018 0
MY Favorite .Net Question For Interview
This are not tidy. Just for rough. In Sha Allah will make it tiddy soon.

1.  DateTime2 Date range 0001-01-01 through 9999-12-31  vs DateTime Date range January 1, 1753, through December 31, 9999 in SQL Server
Ans: https://stackoverflow.com/questions/1334143/datetime2-vs-datetime-in-sql-server

2.  Dictionary  value different types use object as datatype of the eky value

3. If one property of a class is list<> of another class then how to deal with it if we want to initialize it in essential place to avoid Null Reference. See question 17 below.

4. How to create multi valued dictionary rather  than one valued dictionary.


5. Instance Methods as Delegates
6.  Generic:  Base Class Constraint
7. Defference btn logical ("AND, OR") vs  shortcircuit ("AND, OR")repectively

8. Use ref and out Parameters
9. Indexer vs Property Difference
10.Variable Number of Arguments function Arguments

11. How you copy one object to another object . Not reference of the object?

12. Make a simple character stack by a C# class and push pop public member function

13. How to use one constructor to invoke another Constructor and which one will execute first
Optional Arguments vs. Overloading: How optional argument become an alternative to Function Overloading

14. Static class and static method

15. C# 4.0: The Complete Reference: 296 PG: When Are Constructors Called?
 For multilevel hierarchy inheritance : During creation of  child class object which class constructor is executed first? The one in the derived class or the one defined by the base class? Or only one constructor will be called?


16. Dynamic method dispatch/ C# runtime polymorphism: (C# 4.0: The Complete Reference 297 - 305 PG : Base Class References and Derived Objects and Virtual Methods and Overriding)
For multilevel hierarchy inheritance, because of calling the virtual method with any level base class reference variable referring to a any of the child /base class object.
case 1: When both have the virtual method then Object  being referred class method/reference class overridden method will be called?
Case 2:  If a derived class does not override a virtual
method, then, while moving up the hierarchy/down the hierarchy,  the only first override of the method that is encountered is the one executed or only the last? or All from first to last vice versa?




        clsDataprocess  cls2 = new clsDataprocess();// Wrong
static  public   SqlConnection Con = cls2.getConnection253_Mymun(); // cls2 showing the errror

You cannot use an instance variable to initialize another instance variable. Why? Because the compiler can rearrange these - there is no guarantee that cls2 will be initialized before Con , so the above line might throw a NullReferenceException.
                static clsDataprocess  cls2 = new clsDataprocess(); // Correct  put static in both  variable 

               static  public   SqlConnection Con = cls2.getConnection253_Mymun();// Correct


18.Why can't I use alias in a count(*) “column” and reference it in a having clause?

The HAVING clause is evaluated before the SELECT - so the server doesn't yet know about that alias.





19. Null Reference Exception for Class Lists

Answer :


https://stackoverflow.com/a/38511001/2014745

When you create BookList, you haven't actually initialized the list that is its member. You can do this by changing your initialization to: BookList myBookList = new BookList() {bookList = new List<Book>()};

Or by writing a constructor for the BookList class which initializes the list; which would look like this: class BookList { public List<Book> bookList { get; set; } public BookList(){ //New constructor bookList = new List<Book>(); } }



20. Why compile error “Use of unassigned local variable”?

Local variables aren't initialized. You have to manually initialize them.

Members are initialized, for example:public class X { private int _tmpCnt; // This WiLL initialize to zero ... }

But local variables are not:public static void SomeMethod() { int tmpCnt; // This is not initialized and must be assigned before used. ... }
21. If you want to pass multiple different list in a View from ASP .Net MVC Controller Action How can you pass it?
Answer: 
In Action:  ViewBag.MyClassList = new List<MyClass>() ;
 List<MyClass> MyClassList = ViewBag.MyClassList as List<MyClass>;


PtideSys Vivaa Question: 
1. Introduce your selft.
They also introduced their selves. While continuing conversation...
2.  What type of word did you done in previous company?
3.  Asked me about the working procedure of .Net framework.. MSIL and CLR... mixed it  
5. Gave a programe to make the sum and asked it's time and space complexity with various situation. During this session asked me the difference between int type length of ASCII and C# . I said 2 byte and 4 byte, the asked sure, i replied sure..!
4. Garbage collection of .Net framework Dispose. type safety and un safety programming language.
5. Entity framework tasks, codefirst, database first, design first.. Transaction committing with EF
6. Binary search
7. Asked about Singleton patterns --  I said it can be done many ways from that I like JonSkeet c# in depths example with a sealed class and static reference of the same class
8. Factory patterns-- Implemented this with Interface Inheriting
9. Some others question. 
10. Asked about My Stack overflow reputation.
11. Asked if I have used Dictionary, List, Tuple
12. Some other features of OOP 
13. Difference between string And String, I said they are same. Asked what is main defference between String and Stringbuilder class. i said object of string is immutable, if you want to change one cjaracter of C# built in string class object you have to copy it in an char array o have to changed by pointer which is not intutively supported by c#, Also if string a ="7" and string b = "7". They will occupy same memery address. It is a special property of c# string. And All string builder contents object are not like this in built in string class. 
I have gave most of the answers.  
  But only stucked with the answer of Transaction of Enttity framework with question what will be happened when machine face  problem if power goes or network connection goes between program server and database server. I said it can be done manully will complex taskingg... but entity frame work provide easy way to tasking this type of scenario.   And made mistake with the name MISL and CLR
Oh Aro  3 ta question Bad Porche
14. Delegates in c# , keno, ki vabe apply kore
15. Dependency injection ki, keno kore subidha
16. Dynamic method dispatching  khetre ki vabe ki kore..


Asynchronous method ki..
Interface vs abstract class
Ienumarable vs queryable
Linq ar groupby dicilo
Sql ar 2 query
Extendclass ar example
Delegate ki example
JavaScript closure
Javascrip private public , inheritance
Javascrip callback function ar output
Oop ar kisu basic cilo mona portasa na
Event vs delegate

"string" ka reverse korta hoba c# dara





Monday, September 5, 2016

Details Of Split String in Sql :: SQL Server 2014 Version(12.0.4100.1) SQL Server 2008 Version(10.50.1617.0)

September 05, 2016 0
Details Of Split String in Sql  :: SQL Server 2014 Version(12.0.4100.1) SQL Server 2008 Version(10.50.1617.0)

STRING_SPLIT (Transact-SQL) is avail able from SQL Server 2016 

As there is no built in split string function in sql server 2014, 2010, 2008 I have build the bellow function from getting help from stackloverflow.com

1. This is single paged query to under standing split string.

  1. Declare @products varchar(200) = '1,2,3,4,5,6,7,8,9,10'
  2. -- SET @products = SUBSTRING(@products, LEN('ss' + ',') + 1, LEN(@products))
  3. --select @products
  4. Declare @individual varchar(20) = null
  5. WHILE LEN(@products) > 0
  6. BEGIN
  7. IF PATINDEX('%,%',@products) > 0
  8. BEGIN
  9. SET @individual = SUBSTRING(@products, 0, PATINDEX('%,%',@products))
  10. SELECT @individual
  11. SET @products = SUBSTRING(@products, LEN(@individual + ',') + 1,
  12. LEN(@products)-1)
  13. END
  14. ELSE
  15. BEGIN
  16. SET @individual = @products
  17. SET @products = NULL
  18. SELECT @individual
  19. END
  20. END
  21. select @products

Add Choice