Giter Site home page Giter Site logo

mssql-toolkit's People

Contributors

zgudino avatar

Watchers

 avatar

mssql-toolkit's Issues

Idea general FN/SP manejo y salida de cadenas dinámicas

Hoy en una revision SPMakeListOfExpressions quise utilizarlo para obtener lo siguiente:

DECLARE @out nvarchar(max)

EXEC spFoo 'pre_', '1,2,3', ',', @out OUTPUT
SELECT @out
-- pre_1, pre_2, pre_3

Ensayo y Error

Intente utilizando el parametro @delm con el valor pre:

DECLARE @out nvarchar(max)
EXEC SPMakeListOfExpressions '1,2,3', 'pre', @out OUTPUT

SELECT @out
-- '1,2,3'

Sin éxito. Intente diferentes formas @delm = ', pre' y @delm = 'pre ,':

DECLARE @out nvarchar(max)
EXEC SPMakeListOfExpressions '1,2,3', ', pre', @out OUTPUT

SELECT @out
-- '1','2','3'
DECLARE @out nvarchar(max)
EXEC SPMakeListOfExpressions '1,2,3', 'pre, ', @out OUTPUT

SELECT @out
-- '1,2,3'	

Ninguna con éxito.

mssql-server en su idiom no comprende HoF (Higher order Functions) ni Method Chaining tal como JavaScript, y otros lenguaje de alto nivel, hace:

const concatWithArgs = (pre, ...args) =>
  args.reduce((prev, cur) => prev.concat(pre + cur), []).join(', ')


console.log(concatWithArgs('pre_', 1,2,4)) // "pre_1, pre_2, pre_4"

Sugerencia

El procedimiento SPMakeListOfExpressions, opino, no es ideal para esta tarea. Re-escribirlo para un propósito mas general --seria genial-- sin embargo,

  • Quebraría otros SP's dependientes?
  • Realmente nombramiento actual infiere la funcionalidad del SP?

Nombres candidatos podrían ser:

  • SPMakeList
  • SPMakeListOf
  • SPGenerateList
  • SPGenerateListWith

FNStringSplit no interpreta valores de entrada @str mal formados

Utilice los siguientes valores de entrada.

@str = '1'

SELECT [value]
FROM FNStringSplit('1', default)

screen shot 2017-05-26 at 4 23 00 pm

@str = ',1'

SELECT [value]
FROM FNStringSplit(',1', default)

screen shot 2017-05-26 at 4 23 18 pm

@str = ',1,'

SELECT [value]
FROM FNStringSplit(',1,', default)

screen shot 2017-05-26 at 4 23 34 pm

@str = '1,'

SELECT [value]
FROM FNStringSplit('1,', default)

screen shot 2017-05-26 at 4 23 48 pm

Output alternativo de SPs que retornen valor

Capturar output de ejecucion SP utilizando parametro OUTPUT es algo "tedioso".

declare @whsCodes nvarchar(255)
declare @cmd nvarchar(max)

exec SPSplitAndQuote N'02,03,04,05', @result = @whsCodes output

Otra alternativa seria simplemente por asignacion local.

declare @whsCodes nvarchar(255)
declare @cmd nvarchar(max)

exec @whsCodes = SPSplitAndQuote N'02,03,04,05'

Mismo resultado ambos, sin embargo el ultimo ahorras algunas tecleadas y es intuitivo/natural.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.