Showing posts with label content. Show all posts
Showing posts with label content. Show all posts

Thursday, February 16, 2012

Categories and Sub Categories

Hello,
I am working on a web site that makes documents available to students.
I am using tags to classify each document content.
So I have the following tables:
Documents, Tags, DocumentsTags
I also need to categorize the documents:
Subject
|-- Level
|-- Year
For example:
Document_1 - Math > University Level > Second Year
How can I create a table to create such classification?
Thank You,
MiguelHere is one way.
Have a table called Subjects, and add SubjectID to the Documents table with
a foreign key to Subjects (so that you only store "Math" once and it is easy
to update).
Add a column called Level to the Documents table.
Add a column called Year to the Documents table.
"shapper" <mdmoura@.gmail.com> wrote in message
news:24124f92-40c9-411e-8221-17119c78c7da@.j22g2000hsf.googlegroups.com...
> Hello,
> I am working on a web site that makes documents available to students.
> I am using tags to classify each document content.
> So I have the following tables:
> Documents, Tags, DocumentsTags
> I also need to categorize the documents:
> Subject
> |-- Level
> |-- Year
> For example:
> Document_1 - Math > University Level > Second Year
> How can I create a table to create such classification?
> Thank You,
> Miguel|||On Apr 24, 1:31 pm, "Aaron Bertrand [SQL Server MVP]"
<ten...@.dnartreb.noraa> wrote:
> Here is one way.
> Have a table called Subjects, and add SubjectID to the Documents table with
> a foreign key to Subjects (so that you only store "Math" once and it is easy
> to update).
> Add a column called Level to the Documents table.
> Add a column called Year to the Documents table.
> "shapper" <mdmo...@.gmail.com> wrote in message
> news:24124f92-40c9-411e-8221-17119c78c7da@.j22g2000hsf.googlegroups.com...
> > Hello,
> > I am working on a web site that makes documents available to students.
> > I am using tags to classify each document content.
> > So I have the following tables:
> > Documents, Tags, DocumentsTags
> > I also need to categorize the documents:
> > Subject
> > |-- Level
> > |-- Year
> > For example:
> > Document_1 - Math > University Level > Second Year
> > How can I create a table to create such classification?
> > Thank You,
> > Miguel
In the future I might need other categories. I was thinking in
something more flexible then that. Something like:
http://www.sqllessons.com/categories.html
I have two other tables:
Documents > DocumentID, Title, Description
DocumentsCategories > DocumentID, CategoryID
Then I was using Adjacency Model to create the table Categories.
This way I could have a Document associated to one or more categories
and at the same time I could have various levels of categories.
I am using LINQ to SQL so I would like to find a way to make this work
also with LINQ.
I am not sure if this is the best way but after Goggling this is the
closer I could find to solve my problem.
Thanks,
Miguel

Sunday, February 12, 2012

Casting DT_WSTR to integers in SSIS

Hello, all.

Why is it that, despite what is said in the sketchy SQL Help content, it appears to be impossible to cast a string to an integer in the Expression Builder to generate a value for a variable? More specifically, why does the following expression cause an error?

(DT_UI4) (SUBSTRING(@.[User::FullDataPath], LEN(@.[User:Big SmileataPath]) + 1, 2))

I'm iterating over files and using the name of a given file as an ID for an operation. I simply want to grab a file name using the Foreach Loop Container and process that file, while at the same time use the name in another operation. The file name will be something like "2.txt" (full path something like "c:\something\something\2.txt"). I can use string functions to return the file name, which is a number as a string, and it should be no problem to cast that number as a string to a number (an Int32). SQL Server 2005 help has a chart that indicates such a cast is legal.

Maybe it's a crazy thing to be doing. Maybe I have to go about this a completely different way, but casting from "2" to 2 should be possible in the Expression Builder.

Thanks for any help.

I wonder if it doesn't like a period in the data when it tries to cast to an integer....

substring("c:\something\something\2.txt",LEN("c:\something\something") + 1, 2) = "2."|||I see that's not the case, as what I wrote.

Workaround: add a second derived column and in that component, do your cast to DT_UI4. In the first, just perform the substring operation.

I'm not sure that it will allow it in one step because it can't parse the data to determine if it's numeric or not based on the substring operation. That is, when trying to convert the output of substring, you have no idea if it's numeric or not. (YOU do, but SSIS doesn't) When you add a second derived column component, casting a column to DT_UI4 should be straightforward because SSIS is going to imply that it's numeric and can be cast.

I don't like it, but that's my guess. You are always welcome to vent this issue over at http://connect.microsoft.com/sqlserver/feedback.

Phil|||

What's the error message?

-Jamie

|||

Hey, Phil.

Thanks for the response. It turns out that my problem was relying on ALL of my variables being populated at runtime. I didn't bother to specify default values for the variables I had added to my package, because I was populating these variables are runtime. This was working, but once I started using those variables for cast operations, the Expression Builder evaluation mechanism was choking.

What I was doing was this:

1. I was getting a variable folder path from a database and storing that in a variable.

2. I used that folder path variable as an expression for the Foreach Loop Container, wherefrom I derived a full file path (spec) in order to process multiple files.

3. But then I got the brilliant idea of using the folder path and the full file spec to derive a numerical value (based on the file name) and I used that value as an input into an Execute SQL Task to do an auxiliary task.

The bottom line is that once I specified bogus default values at design time (which values were replaced anyway at runtime) for the variables upon which my cast expression depended, the Expression Builder evaluation mechanism was able to validate my cast expressions.

This little idiocy of mine has cost me a few hours of work. But, I should say that I saw nothing about runtime evaluations of design time values DURING DESIGN TIME in the SQL Help.

|||

phanoteus wrote:

This little idiocy of mine has cost me a few hours of work. But, I should say that I saw nothing about runtime evaluations of design time values DURING DESIGN TIME in the SQL Help.

Indeed. So I think you're beig a bit harsh on yourself criticising your actions as idiocy. It doesn't strike me as sensible or intuitive that variables have to be initialised to a value that will never get used. But that's just me.

-Jamie