How To Extract Serialized Data From Strings In One Go In T-SQL

How To Extract Serialized Data From Strings In One Go In T-SQL

Consider the following data:

DECLARE @OrderString VARCHAR(MAX) = '1=1;|2=|3=|4=1;|5=|';

This data was being returned in an externally generated XML file, so out of the control of the developer.

Each element of information is delimited by a pipe |. Within each element, the first number, to the left the equal sign =, represented an Item Number. The second number, to the right of the equal sign, represented an Order Quantity. This could be any number, and if empty, it meant zero.

The developer needed to return this data in form of a table. He also needed to return only the rows with an Item Quantity greater than zero.

read more

How To Create Environment-Aware DacPac Deployment Scripts In PowerShell

How To Create Environment-Aware DacPac Deployment Scripts In PowerShell

I was made “aware” of the idea of environment-aware scripts by a colleague of mine a while ago on a project.

Listening to the principles, I wondered why hadn’t I think about this myself before. It sounded so darn basic, yet so masterfully effective. I guess the more I learn about stuff, the more I realize I don’t know anything at all. But that’s a good thing, right? Surely realizing one does not know stuff helps one keep an open-mind? But anyways, less philosophy, more coding.

An environment-aware script is a script that is aware of its environment. Ah, do I hear reflexive definition alarm bells ringing? Or is it my imagination?

read more