Friday, November 20, 2020

SQL get specific element Count in XML

 Consider this XML


Suppose you want to get count of student ids. You can use SQL to get the count as follows.

declare @xml XML;

set @xml ='<Students>

    <Student>

        <Id>001</Id>

        <Fname>Leesa</Fname>

        <Sname>Humpry</Sname>

    </Student>

    <Student>

        <Id>002</Id>

        <Fname>Clara</FName>

        <Sname>Margrette</Sname>

    </Student>

  </Students>';

select @xml.value('count(/Students/Student/Id)', 'INT') AS 'Count'

Cheers

Samitha

Sunday, November 8, 2020

sql server remove duplicates from query

You can use SQL row_number() function to remove duplicate rows from a query.

Create table Employees (fname varchar(100), lname varchar(100))

Insert into Employees Values 
               ('Tim', 'May')
             , ('Clara', 'Magrette') 
             , ('Clara', 'Magrette')
             , ('Jeff', 'Lawry') 
             , ('Brian', 'Adams')
             , ('Paul', 'Oliver')

As you can see there are duplicate records in the Employees table,

Select * from(
SELECT fname 
       ,lname 
       ,row_number() over (partition by fname , lname order by fname , lname ) as rownum 
FROM Employees 
) result
where rownum= 1 -- selects DISTINCT Employees only

Cheers,
Samitha

Wednesday, October 28, 2020

Remove all table rows except first

You can use jQery to easily remove rows from a given table.

//using jQuery find

$(function() {
   $("#tableId").find("tr:gt(0)").remove();
});
//using empty
$(function() {
  $("#tableId > tbody").empty();
});
The second method is more efficient than the first approach.
Regards,
Samitha

Saturday, October 17, 2020

.Net get plain text from HTML

There can be situations where you want to get plain text from HTML content.  We can use Regex and HttpUtility.HtmlDecode as the easiest way to get plain text shown below.

String plainText =HttpUtility.HtmlDecode( Regex.Replace(HtmlString, "<(.|\n)*?>", "") );


Cheers,

Samitha

Thursday, October 1, 2020

Role does not have permission for this action in QNA Maker

 When you are working with Azure QNA Maker you might get the message "role does not have permission for this action in QNA Maker"

Once you have finished creating  QNA,  the entire page (not the  Refresh Button on the QnAMaker.ai/Create page)  needs to be refreshed and the above message will be disappeared.


Cheers

Samitha

Tuesday, September 15, 2020

using iif to check null

IIf is a function which evaluates all its arguments, Vb net has if operator which works similar to the short circuit  if operator.

 e.g.

varName =   If(objName Is Nothing, "", objName.ToString())

Monday, August 31, 2020

kendo MultiColumnComboBox change selected value

 

If you are working with the Kendo MultiColumnComboBox  you might observe that even if try to reset the selected value you can n't do that.

Even if you try to set value to blank that will not be updated. The way to achieve this is shown as below.


var ddlOptions = $("#ddlOptions").data("kendoMultiColumnComboBox");

ddlOptions.value("");

ddlOptions.trigger("change");


Cheers

Samitha