Wednesday 19 April 2017

MSSQL - Fix Error - Conversion failed when converting date and/or time from character string.



Msg 241, Level 16, State 1, Line 5
Conversion failed when converting date and/or time from character string.

Watch solution on YouTube



To fix it replace
Declare @SQL varchar(max)
Declare @DateFrom Datetime = '1/1/2000'

Set @SQL = 'Select * FROM Users Where StartDate > ' +  @DateFrom

Exec  ( @SQL )

With


Declare @SQL varchar(max)
Declare @DateFrom Datetime = '1/1/2000'

Set @SQL = 'Select * FROM Users Where StartDate > ' + Convert(Varchar, @DateFrom, 101)

Exec  ( @SQL )

Tuesday 18 April 2017

MSSQL - Pass multiple values to single paramenter in stored procedure - pass varchar



Watch on YouTube


1. Stored Procedure

CREATE PROCEDURE PassMultipleNames
    @NameList varchar(max)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    SELECT * FROM Product Where ',' + Convert(varchar(max), @NameList) + ','
     Like '%,' + Convert(varchar(max), Name) + ',%'
END

2. Calling Stored Procedure

Exec PassMultipleNames 'Sofa,Chair,Window'

MVC - Fix Error - 0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'dialog'


 Watch On YOUTUBE


0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'dialog'

to fix it replace


    <script type="text/javascript">
        $(function() {
            $("#Display-Message").dialog({
                modal: true,
                buttons: {OK: function(){$(this).dialog("close");}}
            });
        });
    </script>


with

    @section scripts{
    <script type="text/javascript">
        $(function() {
            $("#Display-Message").dialog({
                modal: true,
                buttons: {OK: function(){$(this).dialog("close");}}
            });
        });
    </script>
       }

MSSQL - Pass multiple values to single paramenter in stored procedure - pass integers


Watch on YOUTUBE


1. Stored Procedure

CREATE PROCEDURE TestProductIDs
    @IDList varchar(max)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    Declare @SQL varchar(max) = 'Select * from Product where ProductID in (' + @IDList + ')';
    Exec (@SQL);
END
GO

2. Calling Stored Procedure

exec TestProductIDs '2, 5, 7'

MVC - @HTML.Label - Add white space


Watch on YouTube



CSS
.White-Space{
    margin-left: .5em;
}

HTML
@Html.Label(" ", new { @class = "White-Space" })