Thursday, March 29, 2012
Data Structures
I am creating a temp table, doing an Bill of Material explosion for a single Order Line Item.
(note: SQL Server 2000)
I used blindman's "accumulator method (click here) (http://www.dbforums.com/showpost.php?p=6239109&postcount=6)" to generate the entire potential BOM tree.
So; step 1 works wonderfully! :beer: Cheers blindman!
Now; I want to remove unwanted nodes (and all their children) from the temp-table. I have a bunch of functions (0 to 1 for each node) that return a Yes or No. If "No", then flag-to-eliminate immediately that branch and don't revisit anything on it (and therein lies my problem). This will leave me with a temp table of only valid nodes.
Since this is recursive, and since it will involve Dynamic SQL (the function name varies), all I can come up with is using a Cursor in a WHILE loop. Even at that; since a CURSOR is point-in-time (ie: values don't change once selected), I'll have to re-check the current temp table values (or create of 2nd temp table of only deleted nodes and repeat a SELECT with NOT EXISTS in it, hmmm).
Since blindman's method generates a table ordered by level, the sequence of processing is pre-determined - unless I can re-order it into a more traditional hierarchy (1 entire branch at a time) and number the levels, in which case the cursor could just skip to the next branch of equal or higher level.
Note: The thought does occur to me I could have an intermediary function (static name) that in turn does the Dynamic SQL. These functions contain the Business Logic that looks at a myriad of column values and relationships in the database and there's no one-size-fits-all decision tree so Dynamic SQL is necessary.
The max cursor size will be maybe 300, and on average 100. Number of levels will normally be 3 or 4, but conceivably could be up to 10. Given the average 100 potential components/sub-assemblies, the final assembly will be about 30. As a periodic background process; it will do 3,000 Order Line Items a day, so I'm figuring 1 second response time per build is adequate (ie: the user's not waiting on it so it doesn't have to be blinding fast) - however why waste?
Anyhow; I thought this might be a fun problem for some Data Structure genius who wants to give a lesson in Relational Programming.
Thanks for looking.
Here's what I have so far:
CREATE PROCEDURE dbo.sp_ExplodeTest1 (@.recID int = 1) AS
/* tbTestH is a table containing an assembly hierarchy.
Assemblies with no parent are Builds.
Assemblies with no children are Components.
It's columns:
MyID int,
ParentID int,
(other descriptive columns)
*/
declare @.t table (
TempNodeID int identity(1,1)
,MyID int
)
-- Seed the tree with the Build's ID.
insert into @.t (MyID) values (@.recID)
/* This populates the temp table with the entire
Assembly for the given build.
It is Ordered By the level in the assembly.
Number of assembly levels is infinite.
For example:
Level 1 = the Build. It comes first
Level 2 = all parents are level 1. Is next (no particular seq)
Level 3 = all parents are level 2. Is next (no particular seq)
etc.
*/
while @.@.Rowcount > 0
insert into @.t (MyID)
select tbTestH.MyID
from tbTestH
inner join @.t rList on tbTestH.ParentID = rList.MyID
where not exists (
select *
from @.t CurrentList
where CurrentList.MyID = tbTestH.MyID)
-- now to display the results so far.
select t.*, tbTestH.*
from tbTestH inner join @.t t on tbTestH.MyID = t.MyID
order by t.TempNodeID
GOOk, well you base code looks fine. But I don't understand what you are trying to do next.
Do you want to use one or more functions to eliminate a branch and all of its children from the dataset you have created? Why not just embed the function in the code you use to populate the table, filtering out all and excluding all those that fail your function tests?
And thanks for the beer.|||Ok, well you base code looks fine. But I don't understand what you are trying to do next.
Do you want to use one or more functions to eliminate a branch and all of its children from the dataset you have created? Why not just embed the function in the code you use to populate the table, filtering out all and excluding all those that fail your function tests?
And thanks for the beer.
You're welcome and well deserved.
I'm not sure about the ultimate possibilities, but if I'm forced with the cursor approach then you are right, I could just skip them. Deleting from the list (or flagging for deletion, since that would have less overhead) only has value if there will be multiple passes, particularly using cursors. In other words, I don't want to repeat work.
I'm realizing that if I have 3000 Order Line Items to process, that I may be able to do them all in one swoop (attaching the OrderLineItemID to each row of course).
Each node of the final build will have a quantity and size that also require calculation. I've defined 15 different methods for calculating quantity and size (example: same as height, same as width, xref-lookup based on height, xref-lookup based on width, xref-lookup based on height/width combo, hard coded at 1, etc.). As well; each component translates (either directly or via a color-xref lookup) into an actual Product ID.
In cases where the node is not a component (ie: has children), it's quantity is used as a multiplier for it's branch. Example; if there's 4 "ladder assemblies", and each ladder has 2 plastic plugs, then the "plastic plug" quantity will be 8. Therefore; the heirchy probably needs to be traversed in sequence - unless I can think of a fancy single update with group-by statement that zooms it all together.
I'm afraid my brain is incapable of looking at the problem and knowing just how to best solve it. I plan to use this remainder of this week to work that out. If someone here is inclined to help out, I'll be most grateful (hey; I'll hand out a whole page of beers for an elegant solution).
Not sure if I've given enough info for the next step. I guess that would be either
1. Ordering this into hierarchical sequence and assigning level numbers
2. Ordering this into hierarchical sequence and assigning high-low node numbers.
Hopefully; with a nice single-SQL update statement (or series of statements like Blindman's WHILE ... INSERT).
My goal isn't the most elegant solution in the world, but one that'll work pretty well for the problem at hand (BOM, MRP, Forcasting system for 35m/yr custom build-to-order manufacturer). By "well", I mean modestly fast, scalable, maintainable, modular, flexible, and accurate.
Thanks!|||So you want to run different function tests depending upon whether the node has children or not?
I still do not see why you think you need a cursor for this.|||So you want to run different function tests depending upon whether the node has children or not?
I still do not see why you think you need a cursor for this.
I believe it's not 1 level of children.....|||So you want to run different function tests depending upon whether the node has children or not?
I still do not see why you think you need a cursor for this.
Each node, regardless of it's status (Tree, Branch, or Leaf) may be either:
1. Always present, given that it's parent is present.
or
2. Optionally present, dependent upon the Y/N result of a custom function.
The fuction for each node is custom only to that node.
Example:
CREATE FUNCTION fn_YN_10 (parms...)
RETURNS bit AS
BEGIN
DECLARE @.MyAnswer bit
SET @.MyAnswer = 1
IF (SELECT MySpecialFeature from tbLineItem where LineItemID = @.parmLineItemID) = "S"
SET @.MyAnswer = 0
RETURN @.MyAnswer
END
The name "fn_YN_10" is a value on the tbAssy. How can I execute that except within a Cursor? Please illuminate?
Also; I need to skip the entire branch if the answer is 1 (ie: No). One method to do that is have the Cursor order everything in hierarchical sequence(everything for a branch together) and process it in traditional loop fashion and with the levels numbered (tree = 1, next branch = 2, leafs = some higher number). If the answer is 1 (false) then it skips everything until the next node at the same or a lower level.
In skipping a branch; I could possibly add to a 2nd table of "Excluded Branches" and have a select with "NOT EXISTS". I believe there's a way to do that HOWEVER; if I have to use a cursor to get the Dynamic SQL anyway, then the first approach makes the most sense.
Note: If I do process 3000 Line items simultaneously, with avg 100 nodes each, we're talking 300,000 nodes. Now it's time to address performance. If I can avoid a Dynamic SQL Cursor, then by all means, that's the way to go. Not sure if doing all at once will make things faster or just cause indexing problems.
One possible solution: I could create an intermediate fuction to which the Function Name (and applicable parms) is passed. That would have a static name. It could then do the Dynamic SQL. That would avoid forcing the processing to use a CURSOR just because of the need for Dynamic SQL. But then it's back to how I can skip a branch without doing a Cursor Loop.|||I believe it's not 1 level of children.....
Correct:
Level 1 = tree
Level 2 or higher = branch
Level 2 or higher = leaf
Children always have higher number so by definition cannot be 1.|||but are we talking about children, grand children, great grandchildren, ect|||but are we talking about children, grand children, great grandchildren, ect
Yes.
Example of the tree representation:
Tree = no parent
Branch = has parent and child
Leaf = no child
01 (tree's root - level 1)
..02 (leaf - level 2)
..03 (branch - level 2)
...04 (branch - level 3)
.....05 (leaf - level 4)
......06 (leaf - level 5)
..07 (branch - level 2)
...08 (branch - level 3)
.....09 (leaf - level 4)
.....09 (leaf - level 4)
..10 (leaf - level 2)
..11 (branch - level 2)
...12 (leaf - level 3)
The child, father, grandfather, great grandfather traverses in the other direction and as such, has limitations
01 (great grandfather)
..02 (child) oops, this doesn't really work ...
..03 (grandfather)
...04 (father)
.....05 (child) oops, this doesn't work either
......06 (child) grandchild? doesn't fit.
etc
So; Child, Father, Grandfather notation works when referencing the lineage of a single elementry component, but not for representing a jagged hierarchy from it's highest level on down.
I see where child needs to be level 01 and so on using this notation method, ergo the confusion.
My bad for using the Child/Parent notation. I should have stuck with the Tree notation. Sorry about the confusion.
Tuesday, March 27, 2012
Data Sources and Connection Managers
Greetings my SSIS friends
This is probably a silly question but what exactly is the purpose of creating Data Sources when it is possible to set up individual connection managers?
Thanks for your help in advance.
If you want to reuse connection managers across different packages, you can create data sources and choose new or existing data connections.Data source with a type of SSIS
I know that you can do this, because I have read about it in MSDN, but I'm not suer about the syntax.
I am creating a report that needs an SSIS type data source. I have deleted the comments in the relevant config files both on my local machine (development) and the reporting services server, and can see SSIS as data type. Now for the tricky bit!
I go to create a new data source. Give it a name, choose SSIS as a data type, and now for the connection string. I "think" I know what I would do if it were a file system SSIS package, but it is stored in the MSDB. What connection string do I use to connect to this data source? There are no DTSX files on the server. Somehow, I presume, I have to talk directly to the MSDB..... Any ideas anyone?
OK, so I gave up on trying to get data out of the MSDB! I capitulated to the MSDN way of doing things and saved my SSIS package as a file system object and attached in that way.
Works like a dream - surprisingly fast. I wonder how it will perform (if at all) when using report snapshots!
If anyone has been successful in reporting over an SSIS, MSDB data source, I would appreciate it if you could post the solution here.
Data Source question
How would be the best way to do this? We are creating reports (the development teams) that run against a Development SQL server (2005). We then send the rdl files to our QA team who then upload the files to their ReportServer (which we do not have access to and this is why we are not deploying the reports). They created their datasource on their ReportServer (using the report manager), but when they go into our reports and try to point to their datasource, they are getting errors.
This is the rdl:
<DataSources>
<DataSource Name="QADataSource">
<DataSourceReference>QADataSource</DataSourceReference>
<rd: DataSourceID>6a2ce78a-db44-4f00-8ec9-6658459ea989</rd: DataSourceID>
</DataSource>
</DataSources>
When I went in and deleted the <rd: DataSourceID> reference, this seemed to work.
Any suggestions?
That is because the dataset is referenced within the current project. If you open the WebBrowser and change the data source pointer to the data source on the report server, it should be fine. The changes to the reference is automatically changed during the VS deployment process.Jens K. Suessmeyer.
http://www.sqlserver2005.de
|||
So what I should be able to do is to supply a user with an rdl file and then they will set up their datasource on their report manager, upload the rdl file and then they should be able to set their own datasource that they created?
This is the functionality that we want.
|||Let them upload the rdl file you provide from Visual Studio and change them the data source to the actual olne on the server.Jens K. Suessmeyer.
http://www.sqlserver2005.de
|||
What we do is to create a set number of datasources on the report server that point to the various DB's we use.
E.g
Datasource 1
Datasource 2
Datasource 3
When creating a report, we set up a shared datasource with the same name as the datasource on the report server. This means when we upload the report, it will use the selected datasource and use the connection details that are stored within it. it doesnt matter what connection details we set in the shared data source within visual studio, it will use the details on the report server.
Thursday, March 22, 2012
Data Report
dates. The date is formatted as MMMM yyyy. My problem is that the layout of the report does not match the data from the table. To make
my problem clear, the report layout is as follows:
Month1 Month2 Month3
Name W1 W2 W3 W4 W5 W1 W2 W3 W4 W5 W1 W2 W3 W4 W5
where W1, W2 etc are the weeks of the month.
Now, let me give you the structure of my table. It is as follows:
Name Month W1 W2 W3 W4 W5
The Query is as follows:
"SELECT DISTINCT EMPNAME, AH1, AH2, AH3, AH4, AH5 FROM STAFFMASTER, STAFFHRS WHERE " & _
"STAFFMASTER.EMPCODE=STAFFHRS.EMPCODE AND STAFFHRS.[PROJECT]='" & cbo1.Text & _
"' AND STAFFHRS.[MONTH & YEAR]>=#" & Format(DTP1.Value, "MMMM yyyy") & _
"# AND STAFFHRS.[MONTH & YEAR]<=#" & Format(DTP2.Value, "MMMM yyyy") & "#"
Now, how will I distribute the data in my report? One important thing, I am building dynamic data report. Please help.
ThanksLooks like it's more of a SQL issue and not Crystal.
Converting rows into columns is a complicated process and needs either a stored procedure or more than one sql statement.. it may need a temp table or dummy table to collect data first and then group it accordingly.
The fast forward solution is this :
.
.
.
Select space(30) "my1", space(30) "my2" , space(30) "my3", h.monthyear "my4", space(30)"my5", space(30) "my6", space(30) "my7",
space(30) "my7", space(30) "my8", space(30) "my9", space(30) "my10", space(30) "my11", space(30) "my12",
sum(h.ah1) april_Ah1, sum(h.ah2) april_Ah2, sum(h.ah3) april_Ah3, sum(h.ah4) april_Ah4, sum(h.ah5) april_Ah5,
0 may_Ah1, 0 may_Ah2, 0 may_Ah3, 0 may_Ah4, 0 may_Ah5, m.empcode
From staffmaster m, staffhrs h
where m.empcode = h.empcode
group by m.empcode, h.monthyear
having h.monthyear = "April 2004" and between (h.monthyear, start_date, end_date)
union all
Select space(30) "my1", space(30) "my2" , space(30) "my3", space(30) "my4", h.monthyear "my5", space(30) "my6", space(30) "my7",
space(30) "my7", space(30) "my8", space(30) "my9", space(30) "my10", space(30) "my11", space(30) "my12",
sum(h.ah1) april_Ah1, sum(h.ah2) april_Ah2, sum(h.ah3) april_Ah3, sum(h.ah4) april_Ah4, sum(h.ah5) april_Ah5,
sum(h.ah1) may_Ah1, sum(h.ah2) may_Ah2, sum(h.ah3) may_Ah3, sum(h.ah4) may_Ah4, sum(h.ah5) may_Ah5,m.empcode
From staffmaster m, staffhrs h
where m.empcode = h.empcode
group by m.empcode, h.monthyear
having h.monthyear = "May 2004" and between (h.monthyear, start_date, end_date)
.
.
.
for each month write a separate sql and just do union all that's going to give you data in column format : like this
my1 my2 my3 my4 my5 my6 my7 my7 my8 my9 my10 my11 my12 april_Ah1 april_Ah2 april_Ah3 april_Ah4 april_Ah5 may_Ah1 may_Ah2 may_Ah3 may_Ah4 may_Ah5 empcode
---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -------
April 2004 40 80 120 160 200 0 0 0 0 0 001
May 2004 40 80 120 160 200 40 80 120 160 200 001
May 2004 40 80 120 160 200 40 80 120 160 200 002
May 2004 40 80 120 160 200 40 80 120 160 200 003
Finally in crystal report you just have to group it based on employee code so that per empoyee there would be only one record in your report.
Thanks
Guru
:wave:|||Ah! This is exactly what I wanted. But what is 'space' in the SQL. And also my1, my2, etc. Also, my table structure is as follows:
Table1:
Code
Month
AH1
AH2
AH3
AH4
AH5
Table2:
Code
Name
The retrieved recordset will be as follows:
Name
Month
AH1
AH2
AH3
AH4
AH5
The report I wish to display is as follows:
Name Month1 AH1 AH2 AH3 AH4 AH5 Month2 AH2 AH3 AH4 AH5
I hope the SQL that you mentioned will display as the above.
Thanks
Thanks|||Hi,
I would like to now what database are you using. I have given you sample of MSSql server ?
Also what do u store in month field ? Just give an actual example because you want to retrieve it based on dates ? Also are you trying to retrieve only one yrs. data or multiple yrs ?
Thanks
Guru
:confused:|||Just wondering how can you display 72 fields in one line. For each month you need to display this info in one line is that true ?
Are you trying to print list of all employees and man hrs worked ?
Thanks
:(|||Originally posted by dilemma
Hi,
I would like to now what database are you using. I have given you sample of MSSql server ?
Also what do u store in month field ? Just give an actual example because you want to retrieve it based on dates ? Also are you trying to retrieve only one yrs. data or multiple yrs ?
Thanks
Guru
:confused:
I use MS Access.
In month field I store the date formatted as "MMMM yyyy".
Example:
Name Month_Year W1 W2 W3 W4 W5
John May 2004 40 40 40 40 24
The user wants to display in the record, the data of the month he picks from a DateTimePicker control and two months ahead of that month. So, for example, if he picks December 2004, then the data of January 2005 and February 2005 should also be displayed.
Thanks|||Originally posted by dilemma
Just wondering how can you display 72 fields in one line. For each month you need to display this info in one line is that true ?
Are you trying to print list of all employees and man hrs worked ?
Thanks
:(
Not 72 fields. There will be only 19 fields, that is, the Name field is displayed only once.
That's right. All employees working on a particular project and the man hours assigned to them. I am attaching a picture of the report how it should be displayed.
Thanks|||Looking at the complexity of your problem If I were you I would do this. Assuming you are planning to create report in Crystal, create report with 3 sub reports for each month. 1 for Current month. 2 for II'nd month. 3 for III'rd month. Add these all 3 reports in one report as a subreport. They each will have different where criteria . eg the current month report would have criteria to fetch only current months data and similarly II'nd one retrieves only II'nd months data and III'rd guy retrieves III'rd months data.
Thanks
:wave:|||That sounds interesting. I am totally new to Crystal Reports. Can you help me on how to create the crystal subreport?
Thanks|||It's pretty easy. Create 3 reports to retrieve records for each month based on appropriate criteria. ONce done create 4'th report and add these 3 reports as subreports using crystal's subreporting features. Input parameter of these reports would be date.
Creation of reports in Crystal is also fairly easy. Just go through help. It has pretty good information.
Thanks|||Thanks for your reply.
Mine is a multiuser system. The database is going to be in the network. So I perfer using the .Dsr as report and not the .rpt. Also, should I use the wizard or should I go for runtime reports?
Thanks.|||I am sorry. I do not know what .Dsr is ? You could use wizard to create crystal report if you are a beginner. I didn't get last part runtime reports ? Doesn't matter even if you have multiuser environment. There is a parameter to open report in exclusive mode or temp copy mode. In your case you would be opening your report in temporary mode. That's it.
Thanks
Sanjay|||.Drs is a report created using the RDC. I have read some articles on Crystal Reporting that the .rpt files increases the size of the compiled program.
Is the parameter to open the report in exclusive mode set inside the crystal report application or is set within the vb code?
Thanks|||There is no doubt that .rpt files increase the size of the package. To open report in temp mode or exclusive mode you need to add something called OpenReport. The syntax is :
Function OpenReport (pFileName As String, [OpenMethod]) As Report
Where,
The OpenMethod parameter can take the values "0" (open by default) or "1" (open temporary copy).
If you do not provide this parameter the report is opened exclusively and it cannot be opened a second time
Thanks|||Ah! That is a very good information. So you suggest that I use .rpt? Thanks for the info.
Thankssql
Wednesday, March 7, 2012
data mining and SS05
I've seen a couple of article on creating and scoring some mining models -- very cool stuff. Is the only way I can do this from an OLAP cube? Can I create, train, and score a model just from relational data?
Thanks!
You can create models directly from cubes using the wizard. Scoring models can be done using an MDX input to a prediction join statement e.g.
SELECT Predict(MyColumn) FROM MyModel
PREDICTION JOIN
<MDX Statement>
ON <bindings>
The data mining functionality in SQL Server 2005 Analysis Services is not restricted to source data in OLAP cubes - you can create, train and query (score) mining models based directly on data in any relational data source. You can find more information, including tutorials at http://www.sqlserverdatamining.com.
Friday, February 17, 2012
Data handling in sysindexes table
I require your help in understanding the way data is maintained in
sysindexes table, I have two doubts,
1) While creating a foreign key constraint for a table, new entry is made in
this table, after dropping this constraint, the entry added with indid equal
to 2 is not deleted from sysindexes table.
2) When we transfer the data from one file group to another, groupid field
value for
for indid equal to 2 still shows the old file group value.
Please execute the following sql statements to simulate the scenario I am
talking about.
create table Department
(DeptId int not null,
DeptName varchar(100))
go
insert into Department
values(1, 'One')
insert into Department
values(2, 'two')
insert into Department
values(3, 'three')
select * from sysindexes
where id = object_id('Department')
-- you will see one entry with indid equal to 0
alter table Department
add constraint PK_DeptId PRIMARY KEY (DeptId)
go
select * from sysindexes
where id = object_id('Department')
-- you will see one entry with indid equal to 1
create table Employee
(EmpId int not null,
EmpName varchar(100),
DeptId int not null)
go
select * from sysindexes
where id = object_id('Employee')
insert into employee
values(1, 'Emp1', 1)
insert into employee
values(2, 'Emp2', 2)
insert into employee
values(3, 'Emp3', 3)
-- you will see one entry with indid equal to 0
alter table Employee
add constraint PK_EmpId PRIMARY KEY (EmpId)
go
alter table Employee
add constraint FK_Emp_DeptId FOREIGN KEY (DeptId)
REFERENCES Department(DeptId)
go
select * from sysindexes
where id = object_id('Employee')
-- you will see two entries with indid values 1 and 2
alter table Employee
drop constraint FK_Emp_DeptId
go
DBCC dbreindex ('Employee', '', 50)
DBCC dbreindex ('Department', '', 50)
select * from sysindexes
where id = object_id('Employee')
-- still you will see those two entries, and indid 2 is not removed from
sysindexes table.
To change the file group, I follow the steps given below, after completing
these steps
groupid value with '2' in sysindexs table for employee object is not getting
updated to
the new file group id value.
1) We drop the employee table's clustered index and recreate clustered index
on the new file group, after this group id field in sysindexes table is
changed
to the new file group in employee table for the row where indid is 1.
2) We drop the foreign key constraint in employee table.
3) We drop the department table's clustered index and recreate clustered
index
on the new file group, after this group id field in sysindexes table is
changed
to the new file group in department table.
4) Foreign key constraint is created again on the employee table by
referring department
table.
5) Execute this statement, select * from sysindexes where id =
object_id('Employee')
6) Groupid field in sysindexes table for employee table against indid value
2 still
shows the old file group id.
This behaviour in sysindexes table is bit confusing, please help me out,
thank you.
Regards,
DevaI think the changes will get reflected when the Server feels that the
statisctics are out of date.
Try
EXEC sp_updatestats
before you check for the change. Its just a guess.
Let me know if this worked.|||Hi,
Data in sysindexes table is not updated even after running
EXEC sp_updatestats
statement, thank you.
Regards,
Deva|||Can you try
DBCC UPDATEUSAGE ('<DBNAME>','<TABLENAME>')
--
"Deva" wrote:
> Hi,
> Data in sysindexes table is not updated even after running
> EXEC sp_updatestats
> statement, thank you.
> Regards,
> Deva
>|||Hi,
Bad luck, even updateusage command does not refresh the data in sysindexes
table, thank you.
Regards,
Deva
"Omnibuzz" wrote:
> Can you try
> DBCC UPDATEUSAGE ('<DBNAME>','<TABLENAME>')
> --
>
>
> "Deva" wrote:
>|||Deva
sp_helpindex 'Employee'
sp_helpconstraint 'Employee'
Yep, it seems to be fixed in SQL Server 2005
select * from sys.indexes
where object_id= object_id('Employee')
Shows only one row
"Deva" <Deva@.discussions.microsoft.com> wrote in message
news:E25567E2-F79B-4516-AD31-6CDC58567F32@.microsoft.com...
> Hi,
> Bad luck, even updateusage command does not refresh the data in sysindexes
> table, thank you.
> Regards,
> Deva
>
> "Omnibuzz" wrote:
>|||1) This is most likely statistics created. What is the name of that "index"?
2) Since statistics doesn't store any pages, the file group is irrelevant. M
ost probably Ms decided
not to change this (dummy) value in case you move the physical table, since
the value should really
be NULL in the first place.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Deva" <Deva@.discussions.microsoft.com> wrote in message
news:E422EDEF-5DA1-4135-97EF-DCA8637E7B63@.microsoft.com...
> Hi,
> I require your help in understanding the way data is maintained in
> sysindexes table, I have two doubts,
> 1) While creating a foreign key constraint for a table, new entry is made
in
> this table, after dropping this constraint, the entry added with indid equ
al
> to 2 is not deleted from sysindexes table.
> 2) When we transfer the data from one file group to another, groupid field
> value for
> for indid equal to 2 still shows the old file group value.
> Please execute the following sql statements to simulate the scenario I am
> talking about.
> create table Department
> (DeptId int not null,
> DeptName varchar(100))
> go
> insert into Department
> values(1, 'One')
> insert into Department
> values(2, 'two')
> insert into Department
> values(3, 'three')
> select * from sysindexes
> where id = object_id('Department')
> -- you will see one entry with indid equal to 0
> alter table Department
> add constraint PK_DeptId PRIMARY KEY (DeptId)
> go
> select * from sysindexes
> where id = object_id('Department')
> -- you will see one entry with indid equal to 1
> create table Employee
> (EmpId int not null,
> EmpName varchar(100),
> DeptId int not null)
> go
> select * from sysindexes
> where id = object_id('Employee')
> insert into employee
> values(1, 'Emp1', 1)
> insert into employee
> values(2, 'Emp2', 2)
> insert into employee
> values(3, 'Emp3', 3)
> -- you will see one entry with indid equal to 0
> alter table Employee
> add constraint PK_EmpId PRIMARY KEY (EmpId)
> go
> alter table Employee
> add constraint FK_Emp_DeptId FOREIGN KEY (DeptId)
> REFERENCES Department(DeptId)
> go
> select * from sysindexes
> where id = object_id('Employee')
> -- you will see two entries with indid values 1 and 2
> alter table Employee
> drop constraint FK_Emp_DeptId
> go
> DBCC dbreindex ('Employee', '', 50)
> DBCC dbreindex ('Department', '', 50)
> select * from sysindexes
> where id = object_id('Employee')
> -- still you will see those two entries, and indid 2 is not removed from
> sysindexes table.
> To change the file group, I follow the steps given below, after completing
> these steps
> groupid value with '2' in sysindexs table for employee object is not getti
ng
> updated to
> the new file group id value.
> 1) We drop the employee table's clustered index and recreate clustered ind
ex
> on the new file group, after this group id field in sysindexes table is
> changed
> to the new file group in employee table for the row where indid is 1.
> 2) We drop the foreign key constraint in employee table.
> 3) We drop the department table's clustered index and recreate clustered
> index
> on the new file group, after this group id field in sysindexes table is
> changed
> to the new file group in department table.
> 4) Foreign key constraint is created again on the employee table by
> referring department
> table.
> 5) Execute this statement, select * from sysindexes where id =
> object_id('Employee')
> 6) Groupid field in sysindexes table for employee table against indid valu
e
> 2 still
> shows the old file group id.
> This behaviour in sysindexes table is bit confusing, please help me out,
> thank you.
> Regards,
> Deva|||On Tue, 9 May 2006 22:26:01 -0700, Deva wrote:
>Hi,
>I require your help in understanding the way data is maintained in
>sysindexes table, I have two doubts,
>1) While creating a foreign key constraint for a table, new entry is made i
n
>this table, after dropping this constraint, the entry added with indid equa
l
>to 2 is not deleted from sysindexes table.
>2) When we transfer the data from one file group to another, groupid field
>value for
>for indid equal to 2 still shows the old file group value.
(snip)
Hi Deva,
The extra row in sysindexes that you see is not for an index, but for
column statistics. If you look at the name column in the output from
SELECT * FROM sysindexes WHERE ...
you'll see that the name start with "_WA_Sys_". For experienced SQL
Server user, this is a clear indication that this is not a real index,
but an entry for column statistics.
I don't think it's documented anywhere, but a more reliable way to
seperate statistics entries from real indexes in sysindexes is to use
the status column:
SELECT *
FROM sysindexes
WHERE id = OBJECT_ID('Employee')
AND status & 64 = 0
Or, even better, don't query the system tables at all. Use the supported
stored procedures instead:
EXEC sp_helpindex 'Employee'
Hugo Kornelis, SQL Server MVP|||Hugo,
> AND status & 64 = 0
How about using INDEXPROPERTY() instead? ;-)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Hugo Kornelis" <hugo@.perFact.REMOVETHIS.info.INVALID> wrote in message
news:9ga362h8at3nk05gmhtj2hnb5hqfq0sop4@.
4ax.com...
> On Tue, 9 May 2006 22:26:01 -0700, Deva wrote:
>
> (snip)
> Hi Deva,
> The extra row in sysindexes that you see is not for an index, but for
> column statistics. If you look at the name column in the output from
> SELECT * FROM sysindexes WHERE ...
> you'll see that the name start with "_WA_Sys_". For experienced SQL
> Server user, this is a clear indication that this is not a real index,
> but an entry for column statistics.
> I don't think it's documented anywhere, but a more reliable way to
> seperate statistics entries from real indexes in sysindexes is to use
> the status column:
> SELECT *
> FROM sysindexes
> WHERE id = OBJECT_ID('Employee')
> AND status & 64 = 0
> Or, even better, don't query the system tables at all. Use the supported
> stored procedures instead:
> EXEC sp_helpindex 'Employee'
> --
> Hugo Kornelis, SQL Server MVP|||On Wed, 10 May 2006 18:58:09 +0200, Tibor Karaszi wrote:
>Hugo,
>
>How about using INDEXPROPERTY() instead? ;-)
Hi Tibor,
Of course! Much better. (sound of hand slapping forehead)
That's what I get for giving up on BOL in frustration and simply
checking sp_helptext sp_helpindex...
Hugo Kornelis, SQL Server MVP
Tuesday, February 14, 2012
Data Flow Task SQL strings
Hi,
I just wanna ask:
I'm creating an SSIS package, a Data Flow Task. I have used OLEDB Source connected to a SQL Server Destination. Now in my OLEDB Source, I have this SQL statement
SELECT FirstName, LastName, Age FROM Employees WHERE (Age > 10) AND (Age < 95)
But what I want is to have the last name and first name concatenated and in proper case(capitalize first letter of the firstname and surname). I also want to TRIM or remove the blank spaces of the field in my SQL statement. How I be able to do this?
I tried using proper(), trim() and ucase() like in MSAccess but no success.
Please help. Thanks in advance.
The OLE DB Source has to use the same syntax as used by the underlying DB engine - in this case SQL Server.
Have a look in BOL for RTRIM(), LTRIM(), SUBSTRING(), UPPER() LEFT(), REPLACE() to get you going.
Alternatively you could carry out this work in the SSIS data-flow using a Derived Column component.
-Jamie
|||Thanks for your reply. I was able to do it using Derived Column. Thanks again and more power...