Showing posts with label current. Show all posts
Showing posts with label current. Show all posts

Wednesday, March 28, 2012

How to translate into SSIS?

Hi everyone,

My current dutie is translate Vb code into SSIS. The following structure is getting me totally crazy:

sql = "SELECT * FROM TABLE1 WHERE FIELD = XXXX"

rs.execute sql

WHILE NOT RS.EOF

STUFF

ANOTHER SELECT AND ANOTHER LOOP

...

...

INSERT AND DELETE STUFF

END WHILE

Which is the best method in order to reach this goal? I'm trying to by means of OLEDB Source Editor connected to Script Component Task on data flow layer but I'm stuck with this.

I don't want to do cursors or something like that with T-SQL.

Thanks in advance for your inputs/help and regards,

Could you use nested FOREACH containers? Store your initial resultset in a variable, then iterate through that, executing the second SQL statement, storing the results in a variable, and using a second FOREACH to iterate that.|||

hi,

using ForEach Loop container on control flow, you mean?

should I use ForEach ADO enumerator, shouldn't?

tia

|||Yes, control flow. Yes, ADO recordset.|||Thank you. I'll test it|||

It's easier than I though. I'll use a Script Task on Control Flow task. Just that task,

I don't need nothing else

|||Could you share the script? Stripped of anything specific to your business, of course.

How to translate into SSIS?

Hi everyone,

My current dutie is translate Vb code into SSIS. The following structure is getting me totally crazy:

sql = "SELECT * FROM TABLE1 WHERE FIELD = XXXX"

rs.execute sql

WHILE NOT RS.EOF

STUFF

ANOTHER SELECT AND ANOTHER LOOP

...

...

INSERT AND DELETE STUFF

END WHILE

Which is the best method in order to reach this goal? I'm trying to by means of OLEDB Source Editor connected to Script Component Task on data flow layer but I'm stuck with this.

I don't want to do cursors or something like that with T-SQL.

Thanks in advance for your inputs/help and regards,

Could you use nested FOREACH containers? Store your initial resultset in a variable, then iterate through that, executing the second SQL statement, storing the results in a variable, and using a second FOREACH to iterate that.|||

hi,

using ForEach Loop container on control flow, you mean?

should I use ForEach ADO enumerator, shouldn't?

tia

|||Yes, control flow. Yes, ADO recordset.|||Thank you. I'll test it|||

It's easier than I though. I'll use a Script Task on Control Flow task. Just that task,

I don't need nothing else

|||Could you share the script? Stripped of anything specific to your business, of course.

how to transfer logins,pwds and current permissions

I need to restore a database and would have orphaned users I notice the
Transfer logins KB articles creates those logins and passwords.. But what
about the security such as if the login was dbowner or sysadmin or
processadmin . I am using SQL 2000I mean the transfer of logins and passwords in the MS KB articles
I believe the special sprocs listed there take care of the logins, passwords
and the SIDs so that the users in the databases are not orphaned but I was
just worried about how to transfer the Server roles. I believe the Database
access roles are within the database
"Tibor Karaszi" <tibor.please_reply_to_public_forum.karaszi@.cornerstone.se>
wrote in message news:e86%23PdHaDHA.2032@.TK2MSFTNGP10.phx.gbl...
> I'm not sure which transfer you are referring to (if you mean a mthod
which keep the correct SID or
> not).
> However, assuming that you do have matcing SID's (this is the first thing
to handle):
> Things like db_owner etc are inside the database, hence are transferred
with the restore.
> I'm pretty certain that the transfer of logins doesn't handle stuff in
master for your logins,
> though (sysadmin etc).
> --
> Tibor Karaszi, SQL Server MVP
> Archive at: http://groups.google.com/groups?oi=djq&as
ugroup=microsoft.public.sqlserver
>
> "Hassan" <fatima_ja@.hotmail.com> wrote in message
news:eRpy$0EaDHA.4028@.tk2msftngp13.phx.gbl...
> > I need to restore a database and would have orphaned users I notice the
> > Transfer logins KB articles creates those logins and passwords.. But
what
> > about the security such as if the login was dbowner or sysadmin or
> > processadmin . I am using SQL 2000
> >
> >
>

Wednesday, March 21, 2012

How to tell if MSDE 2000 is current & patched?

Are there ways to tell if MSDE 2000 is current and patched on a Windows 2000
SP4 server?
We have scanned it with MBSA 2.0 and it doesn't say that SQL 2000 SP4 is
needed (or that it's the latest SP available), and we are pretty sure it's
NOT at SP4 yet.
Thank for any help.
Research Services wrote:
> Are there ways to tell if MSDE 2000 is current and patched on a
> Windows 2000 SP4 server?
> We have scanned it with MBSA 2.0 and it doesn't say that SQL 2000 SP4
> is needed (or that it's the latest SP available), and we are pretty
> sure it's NOT at SP4 yet.
> Thank for any help.
please have a look at http://www.aspfaq.com/SQL2000Builds.asp build chart..
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.16.0 - DbaMgr ver 0.61.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply
sql

Friday, March 9, 2012

how to subtract value at previous row from current row

Hi all,

I need help writing a query that will subtract the values of 2 rows from the same column to display in the result set. Some background information: a table has a sales column that keeps track of sales by the minute, but this is done in a cumulative manner, i.e, sales at row 3(minute 3) = sales recorded @. minute 2 plus sales @. minute 3. Therefor to get the actual sale at min 3, i would have subtract value at row 2 from row 3. make sense? it sounds very easy but I am having a hard time refering back to the previous row and am dealing with more than 1000 rows. i thought about doing a self join on the table but could not get it to do what i want.

would appreciate any help i can get. thanks

Well, here's one methodology - but it is a bit dangerous if you ever delete records from this table. You will need to add a row identifying column (an auto incrementing number) - in this SQL statement I'm presuming it has a increment of 1.

SELECT (TableA.RowNumValue - TableB.RowNumValue) AS Val

FROM

YourTable TableA

INNER JOIN

YourTable TableB

ON

TableB.ID = TableA.ID - 1

This joins the table on itself, matching the previous record based on the autonumber ID (simply called "ID" here).

Once again, if you ever delete records this methodology won't be accurate. Of course, since you are entering the data "cumulatively", deleting data would be a problem for you anyway.

As a side question: why is it necessary to save the data in a cumulative manner? A database is designed for storage and aggregation - you'll save yourself a lot of headache if you simply store the data point as is, and sum the records up in a sql query.

--
Tony Alicea
http://www.theabstractionpoint.com
clarity of mind and creativity in application software development...

|||

Hi Tony,

Thank you so much for your time and input. I will try the self join again based on the method you showed me. The fisrt time I did, I used another field based on time and tried to manipulate but it didn't work....but your method makes sense
And I agree with you, it really doesn't help at all that the data is stored in this manner. Unfortunately, I have limited say in the design of it and this will probably be the last time I use it. But you are absolutely right.

Hey, thanks again.|||

Ah, trying to query a data structure that you didn't design. I've been there. Well, hope it works. If it does don't forget to mark the thread as answered to close it out.

Let us know how it goes!

how to subtract value at previous row from current row

Hi all,

I need help writing a query that will subtract the values of 2 rows from the same column to display in the result set. Some background information: a table has a sales column that keeps track of sales by the minute, but this is done in a cumulative manner, i.e, sales at row 3(minute 3) = sales recorded @. minute 2 plus sales @. minute 3. Therefor to get the actual sale at min 3, i would have subtract value at row 2 from row 3. make sense? it sounds very easy but I am having a hard time refering back to the previous row and am dealing with more than 1000 rows. i thought about doing a self join on the table but could not get it to do what i want.

would appreciate any help i can get. thanks

Well, here's one methodology - but it is a bit dangerous if you ever delete records from this table. You will need to add a row identifying column (an auto incrementing number) - in this SQL statement I'm presuming it has a increment of 1.

SELECT (TableA.RowNumValue - TableB.RowNumValue) AS Val

FROM

YourTable TableA

INNER JOIN

YourTable TableB

ON

TableB.ID = TableA.ID - 1

This joins the table on itself, matching the previous record based on the autonumber ID (simply called "ID" here).

Once again, if you ever delete records this methodology won't be accurate. Of course, since you are entering the data "cumulatively", deleting data would be a problem for you anyway.

As a side question: why is it necessary to save the data in a cumulative manner? A database is designed for storage and aggregation - you'll save yourself a lot of headache if you simply store the data point as is, and sum the records up in a sql query.

--
Tony Alicea
http://www.theabstractionpoint.com
clarity of mind and creativity in application software development...

|||

Hi Tony,

Thank you so much for your time and input. I will try the self join again based on the method you showed me. The fisrt time I did, I used another field based on time and tried to manipulate but it didn't work....but your method makes sense
And I agree with you, it really doesn't help at all that the data is stored in this manner. Unfortunately, I have limited say in the design of it and this will probably be the last time I use it. But you are absolutely right.

Hey, thanks again.
|||

Ah, trying to query a data structure that you didn't design. I've been there. Well, hope it works. If it does don't forget to mark the thread as answered to close it out.

Let us know how it goes!

How to subtract previous value of one column from current value of another column

I have a table like this:

BottomTop

02

46.5

914

1517

In Transact SQL I need to calculate the difference between the current bottom and the previous top. If there is no previous top, then the result would be the current bottom.

So, the result would be 0, 2, 2.5, 1

I must return the value in a table. Thank you all for your help!

Karen

If you have a column to sequence by then you can try something similar to this:

create table test(seq int identity, bottom float, [top] float)

insert into test values(0,2)

insert into test values(4,6.5)

insert into test values(9,14)

insert into test values(15,17)

select CASE WHEN (SELECT B.[top] FROM test B WHERE B.seq = (SELECT MAX(seq) FROM test WHERE seq < A.seq)) IS NULL

THEN

A.bottom

ELSE

A.bottom - (SELECT B.[top] FROM test B WHERE B.seq = (SELECT MAX(seq) FROM test WHERE seq < A.seq))

END

from test A

order by A.seq

|||

Karen,

If you are using SQL Server 2005, you can take advantage of the

new analytic functions more or less like this:

create table T(

primary_key int identity(1,1) primary key,

bottom decimal(10,2),

[top] decimal(10,2)

)

create index T_bottom on T(bottom,primary_key) include ([top])

insert into T values (0,2)

insert into T values (4,6.5)

insert into T values (9,14)

insert into T values (15,17)

go

with Tnumbered as (

select

bottom,

[top],

row_number() over (order by bottom, primary_key) as rownum

from T

)

select

this.bottom,

this.[top],

this.bottom - coalesce(prev.[top],0) as bottom_minus_prev_top

from Tnumbered as this

left outer join Tnumbered as prev

on this.rownum = prev.rownum + 1

go

drop table T

-- Steve Kass

-- Drew University

-- http://www.stevekass.com

mz1derful@.discussions.microsoft.com wrote:

> I have a table like this:

>

> Bottom Top

>

> 0 2

>

> 4 6.5

>

> 9 14

>

> 15 17

>

> In Transact SQL I need to calculate the difference between the current

> bottom and the previous top. If there is no previous top, then the

> result would be the current bottom.

>

> So, the result would be 0, 2, 2.5, 1

>

> I must return the value in a table. Thank you all for your help!

>

> Karen

>

>

|||

SELECT MyTop, MyBottom,
CASE WHEN MyTop = 0 OR MyBottom = 0 THEN 0 ELSE (MyBottom/MyTop) END AS [Difference]
FROM MyTestTable

Adamus

|||

NNTP User wrote:

Karen,

If you are using SQL Server 2005, you can take advantage of the

new analytic functions more or less like this:

create table T(

primary_key int identity(1,1) primary key,

bottom decimal(10,2),

[top] decimal(10,2)

)

create index T_bottom on T(bottom,primary_key) include ([top])

insert into T values (0,2)

insert into T values (4,6.5)

insert into T values (9,14)

insert into T values (15,17)

go

with Tnumbered as (

select

bottom,

[top],

row_number() over (order by bottom, primary_key) as rownum

from T

)

select

this.bottom,

this.[top],

this.bottom - coalesce(prev.[top],0) as bottom_minus_prev_top

from Tnumbered as this

left outer join Tnumbered as prev

on this.rownum = prev.rownum + 1

go

drop table T

-- Steve Kass

-- Drew University

-- http://www.stevekass.com

mz1derful@.discussions.microsoft.com wrote:

> I have a table like this:

>

> Bottom Top

>

> 0 2

>

> 4 6.5

>

> 9 14

>

> 15 17

>

> In Transact SQL I need to calculate the difference between the current

> bottom and the previous top. If there is no previous top, then the

> result would be the current bottom.

>

> So, the result would be 0, 2, 2.5, 1

>

> I must return the value in a table. Thank you all for your help!

>

> Karen

>

>

This code works great if it's static and you already have the answer.

Other than that...Programming 101

Adamus

|||

What do you mean by this? Does the code not work? Why wouldn't the code be static? No problem saying something is wrong but please substantiate, otherwise you are just being negative.

|||

The recordset will ALWAYS be dynamic.

You have no idea what the values will be.

Adamus

|||So are you saying that Steve's code only works for those particular values?|||

Louis Davidson wrote:

So are you saying that Steve's code only works for those particular values?

That is correct. Hence, the hard coding.

You could populate the table dynamically but what would be the point of going to that extreme when a simple solution exists?

...and please don't preach performance on such a petty problem.

Adamus

|||

Louis Davidson wrote:

What do you mean by this? Does the code not work? Why wouldn't the code be static? No problem saying something is wrong but please substantiate, otherwise you are just being negative.

Just because the code works and/or might be clever doesn't mean it's the best solution.

Adamus