Showing posts with label structure. Show all posts
Showing posts with label structure. 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 data?

I am installing MSDE, then a batch file calls osql which calls
script files to build the structure.
How can I easily transfer some table data?
I have a few tables that need some data (not a lot of data but some data in
around 8 tables).
Thanks,
ShaneHi,
Did you meant to transfer data from one MSDE SQL server to another?
then you can,
1. BCP OUT the data from source server in txt files
2. BCP IN to destination server
Have a look into the BCP command in books online.
Note:
If the data trasfer is going to happen in a single server between databases
or with in a database then you can use
Insert into table_name select col1,col2,col3... from table_a, table_b and
then conditions
Thanks
Hari
MCDBA
"SStory" <TheStorys@.TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:O3#GbM1GEHA.2516@.TK2MSFTNGP12.phx.gbl...
> I am installing MSDE, then a batch file calls osql which calls
> script files to build the structure.
> How can I easily transfer some table data?
> I have a few tables that need some data (not a lot of data but some data
in
> around 8 tables).
> Thanks,
> Shane
>

Friday, March 9, 2012

How to structure query

I need to count distinct postalcodes from the customer table and then next to it put the number of times that postalcode was used and the state for the zipcode.

Example output:

85007 / 12 / AZ
90210 / 4 / CA

This is about as far as my knowledge takes me:
select count(distinct postalcode) from customers

Any help generating this query would be greatly appreciated.

thanks!
"I need to count distinct postalcodes"?

Do you really mean to count distinct postalcodes or display distinct postalcodes with the counts and their states?

Your example output seems to indicate the latter.
|||

jeskey wrote:

I need to count distinct postalcodes from the customer table and then next to it put the number of times that postalcode was used and the state for the zipcode.

Example output:

85007 / 12 / AZ
90210 / 4 / CA

This is about as far as my knowledge takes me:
select count(distinct postalcode) from customers

Any help generating this query would be greatly appreciated.

thanks!

I think what you really need is the count of zipz by zip,state:

Select PostalCode, Count(*), State

From <tables.

group by PostalCode, State

|||yes, that is what i needed to do. thanks for your help! much appreciated.

john|||thanks for your help, Rafael answered this post.

How to structure my outer query

I want to select the parent_topic_id from the inner query but i am getting an error though....can someone show me how i should structure these queries please?!?! thank you.....Do I not need to include the Order By or is it in the wrong place?

Msg 1033, Level 15, State 1, Line 25

The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.

Select sti.parent_topic_id

From

(

SELECT sti.parent_topic_id,

st.description_short,

sti.sort_order

FROM sam_topic_items sti

INNER JOIN sam_topic st ON sti.topic_id = st.id

WHERE EXISTS

(

SELECT 1

FROM sam_topic_items sti1

INNER JOIN sam_topic st1 ON sti1.topic_id = st1.id

WHERE st1.type = 'Topic'

AND sti.parent_topic_id = sti1.parent_topic_id

AND sti.sort_order = sti1.sort_order

GROUP BY sti1.parent_topic_id, sti1.sort_order, st1.Type

HAVING COUNT(sti1.sort_order) > 1

)

Order By sti.parent_topic_id

)

Put the [ORDER BY] after the last parenthesis.

|||

I still got "Incorrect Syntax near order"? What am I missing?

Select sti.parent_topic_id

From(

SELECT sti.parent_topic_id,

st.description_short,

sti.sort_order

FROM sam_topic_items sti

INNER JOIN sam_topic st ON sti.topic_id = st.id

WHERE EXISTS

(

SELECT 1

FROM sam_topic_items sti1

INNER JOIN sam_topic st1 ON sti1.topic_id = st1.id

WHERE st1.type = 'Topic'

AND sti.parent_topic_id = sti1.parent_topic_id

AND sti.sort_order = sti1.sort_order

GROUP BY sti1.parent_topic_id, sti1.sort_order, st1.Type

HAVING COUNT(sti1.sort_order) > 1

)

)

Order By sti.parent_topic_id

|||

That was a step forward.

Now the next part of the problem is that when you create a derived table, you have to give it a name. (Recall my remarks in your previous posts about using derived tables?) So add a table name after the last parenthesis and before the [ORDER BY]. (A lot of folks use dt for derived table.)

Also, since the column Parent_Topic_ID is a member of the derived table, you will have to preface the outer query to use the derived table name -NOT [sti].

<ShoulderTap>
As a note: In my opinion, you are jumping ahead too fast, and not taking the time to practice, learn, and understand the help that we are giving you. It is very important to completely understand how to properly use derived tables.
</ShoulderTap>

|||

I changed it to that and it works...I forgot all about the derived tables....opps...I am practicing as I learn....I am just trying to find out how to do things within SQL instead of minipulating SQL through VB.net or C#...You what though? Thank for you help and patience..(Did i spell that right)....

Select dt.parent_topic_id

From

(

SELECT st.id,sti.parent_topic_id,

st.description_short,

sti.sort_order

FROM sam_topic_items sti

INNER JOIN sam_topic st ON sti.topic_id = st.id

WHERE EXISTS

(

SELECT 1

FROM sam_topic_items sti1

INNER JOIN sam_topic st1 ON sti1.topic_id = st1.id

WHERE st1.type = 'Topic'

AND sti.parent_topic_id = sti1.parent_topic_id

AND sti.sort_order = sti1.sort_order

GROUP BY sti1.parent_topic_id, sti1.sort_order, st1.Type

HAVING COUNT(sti1.sort_order) > 1

)

) dt

Order By parent_topic_id

How to structure dimension....?

I have a standard employee-manager tree that I want to use in a dimension. the underlying table has [id] and [parent-id] columns that I've used to create a parent-child relationship in the dimension (via the Usage = /Parent/ field)

Because there are so many top-level members in the tree, I want to create a level above it consisting of the starting letter for manager's last names. This would allow users to select B and see Badden, Browne, Bronson, etc. after which the user could click on Browne and see his employees: Alder, Carson, Domino, etc.

what is the best way of implementing this? I've tried a number of ways without success.including creating a hierarchy consisting of the [Group] (the column witht he first letter of the last name) in the first level and the [parent-id] (Usage = /Parent/, where the the [id]'s NameColumn = /Last Name/) but I can't build it as it pukes with the error:

"Error 1 Dimension 'OrgChart' > Hierarchy 'Hierarchy' > Level 'ParentID' : The source attribute of the level is marked as 'Parent'. 0 0 "

can anyone help?

You cannot mix and match other attributes in with a parent child hierarchy.

The only way I know of to implement this is to add the records for the A-Z members to your dimension table and link them up appropriately in there. If you did not want to mix these records in with "real" employees you could create a separate table and link it in with a union query in a view or a named query in the DSV.

Wednesday, March 7, 2012

How to structure a FTS query.

Hi
I'm having some problems structuring my query to execute with relevant
results. Basically I have 1 table that has been FT indexed. The table has a
CountryName, GroupName and ItemName.
A user may enter a query as 'India houshold expenditure'. India is in the
CountryName column and household expenditure in the ItemName colum.
When I use a FREETEXT I end up with all GroupNames and ItemNames that
contain household expenditure. Using CONTAINS produces an error:
Syntax error near 'household' in the full-text search condition 'India
household expenditure'.
Alternatively the user may just enter 'India' or 'household consumption
expenditure'
I am expecting my resultset to be in the case of a query for 'India
household consumption' to show only India where household consumption appears
in the ItemName. Not India and ItemNames where consumption or expenditure
appear individually.
Does anyone have suggestions on how I should go about structuring my
procedure to capture the query cases describe above? Any feedback would be
greatly appreciated.
Regards
Craig
I think what you will have to do is parse your search phrase looking for the
country, perhaps through a look up table. If it detects a country in the
phrase it will issue the following query
select *from tableName where contains(CountryName, 'CountryName') and
(contains(GroupName,'Remainder of search phrase') or
contains(ItemName,'Remainder of search phrase'))
If, you are only interested in ItemName containing the remainder of the
search phrase you could reduce this to
select *from tableName where contains(CountryName, 'CountryName') and
contains(ItemName,'Remainder of search phrase')
"Craig" <Craig@.discussions.microsoft.com> wrote in message
news:BAC003AD-41C6-4B18-B63E-0914BCCF79DB@.microsoft.com...
> Hi
> I'm having some problems structuring my query to execute with relevant
> results. Basically I have 1 table that has been FT indexed. The table
> has a
> CountryName, GroupName and ItemName.
> A user may enter a query as 'India houshold expenditure'. India is in the
> CountryName column and household expenditure in the ItemName colum.
> When I use a FREETEXT I end up with all GroupNames and ItemNames that
> contain household expenditure. Using CONTAINS produces an error:
> Syntax error near 'household' in the full-text search condition 'India
> household expenditure'.
> Alternatively the user may just enter 'India' or 'household consumption
> expenditure'
> I am expecting my resultset to be in the case of a query for 'India
> household consumption' to show only India where household consumption
> appears
> in the ItemName. Not India and ItemNames where consumption or expenditure
> appear individually.
> Does anyone have suggestions on how I should go about structuring my
> procedure to capture the query cases describe above? Any feedback would
> be
> greatly appreciated.
> Regards
> Craig