Buscar contenidos

jueves, 23 de julio de 2020

Using comma separated value parameter strings in SQL IN clauses

https://www.codeproject.com/Tips/584680/Using-comma-separated-value-parameter-strings-in-S


Using the code

Simple:
DECLARE @LIST VARCHAR(200)
SET @LIST = '1,3'
SELECT Id, Descr FROM CSVDemo WHERE Id IN (SELECT * FROM dbo.CSVToTable(@LIST))

...

/****** Object:  UserDefinedFunction [dbo].[CSVToTable]    Script Date: 04/28/2013 10:45:17 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[CSVToTable] (@InStr VARCHAR(MAX))
RETURNS @TempTab TABLE
   (id int not null)
AS
BEGIN
    ;-- Ensure input ends with comma
 SET @InStr = REPLACE(@InStr + ',', ',,', ',')
 DECLARE @SP INT
DECLARE @VALUE VARCHAR(1000)
WHILE PATINDEX('%,%', @INSTR ) <> 0 
BEGIN
   SELECT  @SP = PATINDEX('%,%',@INSTR)
   SELECT  @VALUE = LEFT(@INSTR , @SP - 1)
   SELECT  @INSTR = STUFF(@INSTR, 1, @SP, '')
   INSERT INTO @TempTab(id) VALUES (@VALUE)
END
 RETURN
END
GO

miércoles, 1 de julio de 2020

The jQuery replacement for select boxes

https://select2.org/

---

    $("#id_select_producto_interes").select2({
        language: {
            searching: function () {
                return "Espere por favor...";
            }, inputTooShort: function () {
                return 'Digite almenos 5 caracteres...';
            }, noResults : function () {
                return 'No hubo resultados';
            }
        },
        minimumInputLength: 5,
        ajax: {
            url: "/Shared/ListadoProductos",
            type: "post",
            dataType: 'json',
            delay: 250,
            data: function (params) {                
                var query = {
                    descripcionProducto: params.term,
                    type: 'public'
                }
                return query;
            },
            processResults: function (response) {   
                /*return model text & id*/
                return {
                    results: response
                };
            },
            cache: true
        }
    });

SQL SERVER – 2005 – Start Stop Restart SQL Server From Command Prompt

https://blog.sqlauthority.com/2007/09/09/sql-server-2005-start-stop-restart-sql-server-from-command-prompt/

SQL SERVER – 2005 – Start Stop Restart SQL Server From Command Prompt

Very frequently I use following command prompt script to start and stop default instance of SQL Server. Our network admin loves this commands as this is very easy.
Click Start >> Run >> type cmd to start command prompt.
Start default instance of SQL Servernet start mssqlserver
SQL SERVER - 2005 - Start Stop Restart SQL Server From Command Prompt netstart
Stop default instance of SQL Servernet stop mssqlserver
SQL SERVER - 2005 - Start Stop Restart SQL Server From Command Prompt netstop
Start and Stop default instance of SQL Server.
You can create batch file to execute both the commands together.
SQL SERVER - 2005 - Start Stop Restart SQL Server From Command Prompt netstartstop
Reference : Pinal Dave (https://blog.sqlauthority.com)