Showing posts with label definition. Show all posts
Showing posts with label definition. Show all posts

Sunday, February 19, 2012

Array as procedure parameter

I have a shift definition table with the columns:

shift_id: shift's id

shift_name: shift's name

shift_number_of_day: shift's "position" on the day

initial_hour: shift's initial hour

final_hour: shift's final hour

The shift definition depends on the company: company A may have 2 shifts, and company B may have 3 shifts, for example.
I need to load a dimension table, dim_time, that should have a row for each hour of each day of a specific year. I would have

alternate_time_key ... shift_name ...
1/1/2006 01:00:00 GraveYard
1/1/2006 02:00:00 GraveYard

and so on, until it reaches the end of the year.

So in my procedure to load the dimension table, I would have something like

IF (@.alternateTimeKeyHour >= @.paramShift1InitialHour) AND (@.alternateTimeKeytHour <= @.paramShift1FinalHour)
BEGIN
SET @.shiftName = @.paramFirstShiftName;
SET @.shiftNumberOfDay = 1;
END
ELSE IF (@.alternateTimeKeyHour >= @.paramShift2InitialHour) AND (@.alternateTimeKeyHour <= @.paramShift2FinalHour)
BEGIN
SET @.shiftName = @.paramSecondShiftName;
SET @.shiftNumberOfDay = 2;
END
.
.
.

The problem is that I would have a variable number of shifts (variable number of parameters!)...
The only solution I could think was using an array, but as far as I could see it's not possible to pass
an array as a parameter to a procedure. Is this right? Is there a better solution to do this? Can anyone help me please?

Thank you!

Personally, I always use XML for this type of thing. You can then use OPENXML in the stored procedure to turn the xml into a table that you can join to.

Here is a great article about your choices for passing an array to a stored procedure.

http://www.sommarskog.se/arrays-in-sql.html

|||Thank you Ryan!

Sunday, February 12, 2012

Are there any MS SQL operations that are not transactional ?

I pretty new to MS SQL.
Long ago I heard that some MS SQL data definition operations are not
transactional.
Executed in the transaction's boundaries their results persists even if
transaction rolls back.
Could anyone ellaborat on that subject ?
Thank you.Table variables are non-transaction, that is to say, they aren't affected by
transaction scope - there is still logging on the transaction log.
declare @.tb table ( mycol int )
insert @.tb values( 1 )
begin tran
update @.tb set mycol = mycol + 1
rollback tran
select * from @.tb
The above returns 2, if you use a temporary table or permanent table you
will get 1...
create table #tb ( mycol int )
insert #tb values( 1 )
begin tran
update #tb set mycol = mycol + 1
rollback tran
select * from #tb
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"Marek" <nospam@.nowhere.com> wrote in message
news:e2n$QpL0FHA.3780@.TK2MSFTNGP12.phx.gbl...
>I pretty new to MS SQL.
> Long ago I heard that some MS SQL data definition operations are not
> transactional.
> Executed in the transaction's boundaries their results persists even if
> transaction rolls back.
> Could anyone ellaborat on that subject ?
> Thank you.
>|||TRUNCATE table.
"Marek" <nospam@.nowhere.com> wrote in message
news:e2n$QpL0FHA.3780@.TK2MSFTNGP12.phx.gbl...
>I pretty new to MS SQL.
> Long ago I heard that some MS SQL data definition operations are not
> transactional.
> Executed in the transaction's boundaries their results persists even if
> transaction rolls back.
> Could anyone ellaborat on that subject ?
> Thank you.
>|||That's incorrect. TRUNCATE participates in a transaction like any other
DML operation (table variables excepted).
David Portas
SQL Server MVP
--|||> TRUNCATE table.
?
CREATE TABLE MyTable(Col1 int NOT NULL)
INSERT INTO MyTable VALUES(1)
BEGIN TRAN
TRUNCATE TABLE MyTable
ROLLBACK
SELECT Col1 FROM MyTable
DROP TABLE MyTable
Hope this helps.
Dan Guzman
SQL Server MVP
"JT" <someone@.microsoft.com> wrote in message
news:%23LIQ8RM0FHA.1192@.TK2MSFTNGP10.phx.gbl...
> TRUNCATE table.
> "Marek" <nospam@.nowhere.com> wrote in message
> news:e2n$QpL0FHA.3780@.TK2MSFTNGP12.phx.gbl...
>|||You can have non transaction DDL inside a transaction if you use xp_cmdshell
and osql to execute the DDL. Extended stored procedures are not included in
a transaction. But if you are looking for a bug or "feature" where plain DDL
(table variables excepted as mentioned in the other posts) is not
transactional, there is none I am aware of in SQL Server 2000, although
there might have been in long ago versions like 6.0 or 6.5.
Jacco Schalkwijk
SQL Server MVP
"Marek" <nospam@.nowhere.com> wrote in message
news:e2n$QpL0FHA.3780@.TK2MSFTNGP12.phx.gbl...
>I pretty new to MS SQL.
> Long ago I heard that some MS SQL data definition operations are not
> transactional.
> Executed in the transaction's boundaries their results persists even if
> transaction rolls back.
> Could anyone ellaborat on that subject ?
> Thank you.
>|||I stand corrected.
"JT" <someone@.microsoft.com> wrote in message
news:%23LIQ8RM0FHA.1192@.TK2MSFTNGP10.phx.gbl...
> TRUNCATE table.
> "Marek" <nospam@.nowhere.com> wrote in message
> news:e2n$QpL0FHA.3780@.TK2MSFTNGP12.phx.gbl...
>

Thursday, February 9, 2012

Are other vendors buying into this?

Microsoft wants to make its Report Definition Language (RDL) an industry
standard. how's that going? have other vendors bought into this yet?rob <rob@.discussions.microsoft.com> wrote in message news:<D1755B96-8E99-4199-B7CE-BAD5CCD93B47@.microsoft.com>...
> Microsoft wants to make its Report Definition Language (RDL) an industry
> standard. how's that going? have other vendors bought into this yet?
There are a couple of commercial companies that have published
designers / add ins for reporting services (Cizer & ProClarity) but
with Microsoft, there is method to their madness.
MXS bought out ActiveViews in April which I believe has a designer as
well. Look for something to come from this purchase. It is funny but
the ActiveViews web site does not have anywhere on it that tells you
how you can get their product.
Also I think that changing the mindset corportations have with regards
to delivering enterprise level solutions is what Microsoft is ttrying
to do. For instance Microsofts MOM 2005 software utilizes Reporting
Services to report against its database. You don't need to install it,
but you get out of the box reports if you use it. Where I work at
there is another major vendor, I cannot think of at this moment, that
told us that they will be using Reporting Serives in their next
release. You can expect a lot of vendors going that route. The only
question I have is that since this is only for SQL Server, what will
the
software publishers that write against Oracle, SAP, Informix etc. do.
Business Objects will be loosing some market share to Microsoft in the
SQL Server market. I know there are a lot of vendors now that pay
Business Objects to include Crystal Reports in their product. Look for
more and more of the enterprise level applications come out with
Reporting services support and reports built in.