Cincinnati SQL User Group

January 11, 2009 at 10:03 PMRampidByter

powershell_2

 

Last Thursday I went to my first Cincinnati SQL user group meeting. The meeting was suggested to me by my co-worker, and the topic was something I've been interested in. When I installed Windows Server 2008 i was excited to see that Powershell was included, it was also on my Vista PC’s, but I never really took the time to check it out.

I had been warned that at this particular meeting a past employee had been given a hard time for being a .Net developer. I thought they were pulling my chain so of course i decided I'm going to wear the .Net shirt that is completely black with the large bold white font .Net on the front.

We get to the meeting and i start to see one by one people heading into MAX training for the meeting. We both get out of the car and head in. First thing i notice is that everyone is dressed nicely and I'm the one in my carheart jacket, .net shirt, and cargo jeans. From there the speaker Arie Jones starts to give background on himself establishing his credentials with good background detail on growing up the computer geek who went to camp, and was one of the young developer of his time during high school. I couldn’t help but note a surprising similarity between his background in mine. I went to a college course on DOS when i was about 9 years old, did co-op in high school when i was 16 becoming the fourth youngest worker at SDRC, and Arie then mentioned he joined the military to do something different. Something i also did in my life, but again that is where the similarities end.

During the presentation we went through the basics of Powershell, that uses it provides, some overall benefits, and really just touched the surface of the technology. What i gained was understanding how to launch Powershell by entering Powershell into the command prompt. From there you can load/include a script into the environment, and then given the ability to call functions defined within the function. It’s pretty easy to load a script file just include the path with “. ./Functions.ps1” and all functions from that script file will be loaded into the environment.

 Untitled

The syntax was what really caught me off guard since Powershell has been touted as bringing .Net to the command line shell scripting level. The syntax is anything but .Net styled, and in fact reminds me heavily of a PHP and C++ hybrid scripting language with Unix styled functionality. Mainly the way all variables are prefixed with $, and how equality checks are done with ‘-eq’ for equals, ‘-le’ less than or equal to, and the general format of the curly bracket and semi-colon syntax. You can pipe things in Powershell as you could in Unix/Linux systems. One friend of mine actually made a comment in jest that Microsoft has finally given something that Unix gave some thirty years ago how novel of them.

From what i can tell initially, keep in mind I'm a complete novice to Powershell, the variables are completely lazy in declaration, just use as you go, and can be either object or simple data type. From there you can make calls to functions only available in .Net assemblies, such as the Reflection namespace, and actually use the functions exposed to that namespace. While there isn’t anything much I can do with Powershell that i couldn’t do in .Net it is nice to know that should i wish i could create some seemingly simple scripts to carry out some tasks without the need to compile and recompile assemblies to do the same. I was thinking of updating my Remote Desktop port changing application to a simple Powershell script, and another one to send an SMS notification in the event my IP address changes to my phone so i could log in remotely to the new address. Again, nothing i couldn’t do with .Net, but merely something to try the new technology out and get at least acquainted.

Well, i do have to share one thing. I of course was called out during the SQL user group presentation, asked about dynamic data pages, and polled about our usage of LINQ. This was shortly after Arie asked whether there were any developers in the room, and of course my buddy and I were the only two. Didn’t help my .Net kind of gave me away on that one, and during the whole presentation besides calling server admin’s ‘Monkeys’ the presenter also seemed to be directly addressing both of us developers throughout the entire thing.

After the presentation i will admit that the lunch was kind of awkward, at least until the one guy from Western Southern came to sit with us, and from then on we were engaged in conversation with the three user group founders. I mostly sat in on the conversation regarding SSIS packages, but it was hard to focus after totally getting swag. I got second dibs of the table full of Microsoft products, books, shirts, and assorted drinking containers. It was awesome, i got a sweet Microsoft thermas AND was given a awesome server center operations manager book. I heard they were going to have the next group meeting on analysis services and i have to admit i hope to make this a regular group to attend, so long as the topics are interesting.

Posted in: Microsoft | SQL | User Group | Utilities

Tags:

Execute SQL Stored Procedure within a Stored Procedure.

June 25, 2008 at 1:50 AMRampidByter

I know anyone who uses a SQL database, or maybe even MySQL does stored procedures at some point. I also know at some point they’re going to want to abstract stored procedures to reduce redundancy. Anyway, if you’re looking to call an existing stored procedure from within a stored procedure it’s as simple as this…

InsertCustomerAddress – stored procedure being built

. . .

@customerID    bigint,
@address1 varchar(120),
@address2 varchar(100) = NULL,

. . .

DECLARE @returnValue smallint

EXECUTE @returnValue = InsertAddress @ address1, @address2

INSERT INTO dbo.CustomerAddress
(
                CustomerID,
                AddressID
)
. . .

You see that I declared a value of @returnValue in the datatype smallint. From there I simply executed another stored procedure that returns the unique ID created by inserting a new Address record. From there I used that return address ID to insert into my customer address reference table along with the customers ID.

That seems to be about it. Just call the Execute function from within the stored procedure; you don’t necessarily need to set a value to capture the return value as many procedures may not return any values. Just call Execute with a space, the name of the stored procedure to call, and the parameters to pass in. It is possible to put the keyword ‘output’ next to each parameter whose values will be altered within the called procedure.

Posted in: SQL

Tags: