|
This is a rediculously retarded question and I should be able to do this by now, but I can't get my head around it: Given a data field [YearMonth] [int] with format yyyymm How do I get the last day of that month with a format of yyyy-mm-dd? Edit: in MS-SQL. Sorry. Agrikk fucked around with this message at 20:50 on Apr 2, 2012 |
# ? Apr 2, 2012 17:35 |
|
|
# ? May 14, 2024 22:08 |
|
In MySQL at least, SELECT LAST_DAY(STR_TO_DATE(datecolumn, "%Y%m")).
|
# ? Apr 2, 2012 17:56 |
|
Agrikk posted:This is a rediculously retarded question and I should be able to do this by now, but I can't get my head around it: You can just convert the Year Month to a date time (with a day of 1) and then add a month to it (to get the 1st day of the next month) and then minus a day. So it'd be: code:
JeansW fucked around with this message at 21:23 on Apr 2, 2012 |
# ? Apr 2, 2012 21:20 |
|
JeansW posted:You can just convert the Year Month to a date time (with a day of 1) and then add a month to it (to get the 1st day of the next month) and then minus a day. Oh. Of course. Duh. Thanks!
|
# ? Apr 2, 2012 23:33 |
|
I need to learn SQL on my own time, for a new job I'm about to start within the firm I already work in. Background: - Massive multinational firm. - Database that I will be working with currently has over 16 million records. - Each record has approximately 200 fields available in it (for the average record though, only 10-50 of those fields are populated though). - I use this database as an enduser currently, i.e. inputting data, querying data using the enduser GUI, amending data etc. I know the database's structure pretty well, i.e. in which table things belong etc, e.g. the field/attribute Country belongs in table/concept Product. I'll be required to do things like run queries similar to: Pull out all records that have ExpiryDate<TODAY, Type=Common, Country=FR Pull out all records that have Status=Active, TaxType≠NULL I am currently on leave. I'd like to basically understand the syntax of SQL and the basic manner in how and where to enter such queries. Can someone recommend me a decent beginners guide online?
|
# ? Apr 4, 2012 18:53 |
|
Steakandchips posted:I need to learn SQL on my own time, for a new job I'm about to start within the firm I already work in. Personally, I really like Tizag's tutorials: http://www.tizag.com/sqlTutorial/ They're a great starting point and should definitely get you through the basics. After that, stackoverflow is a great resource for weird one-off questions.
|
# ? Apr 4, 2012 20:52 |
|
Alright, I thought I was done with the Access related questions (is there a better place to ask them in SH/SC?), but I have one I can't figure out. I have a form that acts as a front-end search tool for a SQL database. This form is a 'split form' - the top is a form with a couple of comboboxes I programmed up to search fields, and the bottom is a datasheet. When you enter more than 4 characters in the combobox, some VB code runs a SQL query to populate its dropdown, then you select your record from the dropbox, and then a query runs to populate the datasheet with the relevant records. then I setfocus back to the combobox. all works fine. I've run into a problem though. A user wants to export the contents of the datasheet to excel, and she's just doing the standard 'external data->export to excel' steps. What's exporting, though, is the recordset for my combobox, rather than what's in the datasheet. Can't figure out how to export the datasheet. only thing that works is if I switch from split form view to datasheet view, but of course this isn't ideal from an ease of use standpoint. Any thoughts?
|
# ? Apr 4, 2012 22:40 |
|
DankTamagachi posted:Personally, I really like Tizag's tutorials: You sir, are a scholar and a gentleman.
|
# ? Apr 4, 2012 23:39 |
|
Any oracle guys in here? I'm trying to figure out if a user can create tables to a non default tablespace. I'm testing this install and they added a "feature" to install tables to a non default tablespace. Its more than likely the code is broke, but I started thinking about it and i've never used anything other than the default tablespace.
|
# ? Apr 5, 2012 15:08 |
|
Teh z0rceror posted:Any oracle guys in here? Yea you can. Check out the generated DDL for one of your tables in a tool like SQL Developer - there's heaps of storage options that you can specify if you want, but never really need to. code:
|
# ? Apr 5, 2012 19:33 |
|
mindphlux posted:Any thoughts? I can't say for sure without seeing the app but is it maybe because the combobox has focus? I have never used that feature of Access so I can't say for sure. To ensure it does what you want it to do you could look in to the Excel object model and create your own export to Excel function, and add a button to your form. It's really quite easy. My one clue is 'CopyFromRecordset'. I have seen too many people iterate through recordsets (takes forever) instead of using this function which takes a tiny fraction of a second.
|
# ? Apr 6, 2012 19:13 |
|
G-Dub posted:I can't say for sure without seeing the app but is it maybe because the combobox has focus? I have never used that feature of Access so I can't say for sure. yeah, that was my thought too. I hadn't come across copyfromrecordset, thanks for the tip. I'll probably end up adding a button if the client can't deal with switching to datasheet view.
|
# ? Apr 6, 2012 23:24 |
I'm writing something that needs to save to and pull from dictionary information in a database. E.g. I'll be adding this: http://en.wiktionary.org/wiki/deus#Inflection into a table along with a bunch of other words that decline along a similar vein. Normally there'll only be one value per field, i.e "Nominative Singular" would just be "deus" and nominative plural would just be "dei" on the vast majority of words I'm looking at. Except I do need to be able to handle multiple words per field for irregular words such as this one. My question is, how should I handle it from a DB perspective? Have the field be long enough to contain 'dei.di.dii' and attempt to explode (un-delimit) every field I query? Or create an extra field with a status that denotes that one of the entries in that row has multiple acceptable forms? Or create an extra field for every entry saying the same? Or should the field identify which entries have extra forms by way of: 111112323133 (e.g. how many forms per field, 1 being standard, and just count like that), or some other more mathematically-efficient identifier? Or should I skip the delimited thing entirely and just create a custom table for irregular forms and manually add 3 fields per declension, meaning that every noun will have 36 fields, with a minimum of 12 used (and the remaining 24 normally empty), and grab them all every time I query that irregular noun? Obviously the database would be more efficient if I just crammed more info into the field and delimited it, to be processed by the script. Should I then just add an extra field for every row (regardless of regularity) and just state using a hex value (or something) how many values there are in each field?
|
|
# ? Apr 7, 2012 05:50 |
|
Sulla-Marius 88 posted:I'm writing something that needs to save to and pull from dictionary information in a database. I don't understand enough about Latin to be able to completely understand the problem domain, but I will attempt to give you a couple of pointers: Storing comma-delimited arrays (as in your "store 'dei.di.dii' in one column" idea) is not generally a good idea. It makes it enormously complicated to extract subsets of that information or filter by it in a query. For example, if you wanted to know how many words have both a form that ends in "i" and another form that ends in "ii" you would have to write a really complicated query to try to work it out. A case can be made for doing it, but only if you are sure you'll never want to do anything other than retrieving the data in the column in the same form you put it in (i.e. you won't want to retrieve only parts of it, and you won't want to involve the contents of the column in SQL logic, such as a WHERE clause). If there are multiple possible versions for each word (or for each word in each possible grammatical situation) then you may be best served by having two tables, Word and WordVersion. Here WordVersion has a foreign key back to Word. If a word has only one version then there's just one corresponding row in each table. If a word has n versions then there's one row in Word but n rows in WordVersion. I am guessing that this would work better than special-casing irregular words by giving them their own table, but I can't guarantee this. Like I said, I don't know much about Latin.
|
# ? Apr 7, 2012 06:09 |
|
I have a question that I haven't been able to find the answer to, though I'm pretty sure I'm just not phrasing it correctly for it to come up on google. What is the best way to create a table schema where I will have a variable number of column entries? Should I just put a maximum bound on it and have unfilled entries default to NULL? To be specific, I want to have recipes that are searchable by ingredient. The list of ingredients can vary in size, though a reasonable bound would be 15 or 20 ingredients. My best approach is to have a recipe table with columns for ingredients_id0-19 and a corresponding ingredients table.
|
# ? Apr 7, 2012 09:20 |
|
FamDav posted:I have a question that I haven't been able to find the answer to, though I'm pretty sure I'm just not phrasing it correctly for it to come up on google. You need a table RecipeIngredient which contains the ingredients for recipes - one row per ingredient. Each row of the table will specify one ingredient, as well as indicating the recipe to which it corresponds (a foreign key). Having a hard-coded set of columns is a design error. It will make it hard work to search for, say, recipes using a specific ingredient. (Imagine writing a query with a WHERE clause that says Ingredient0 = 'tomato' OR ingredient2 = 'tomato' OR ingredient3 = 'tomato' OR ...) And if you increased the number of columns you'd have to rewrite all your queries. In comparison, if you set up a RecipeIngredient table as I suggest, you can join Recipe to RecipeIngredient and search in the RecipeIngredient table for a specific ingredient. Much simpler and there is no artificial restriction on number of ingredients. You might want to have an Ingredient table and have RecipeIngredient serve as a cross-reference table that has foreign keys to both tables. (Then your RecipeIngredient table would have maybe 3 columns: Recipe, Ingredient, and Quantity.)
|
# ? Apr 7, 2012 09:32 |
|
Hammerite posted:You need a table RecipeIngredient which contains the ingredients for recipes - one row per ingredient. Each row of the table will specify one ingredient, as well as indicating the recipe to which it corresponds (a foreign key). Ohhh, that makes so much more sense. Thanks.
|
# ? Apr 7, 2012 18:09 |
|
Movies table: MovieID, Movie Actors table: ActorID, Actor Relationship table: RelationshipID, ActorID, MovieID So I have a database with these three tables. Is there a Join query I can write that will return a movie and all of the actors in the movie in a single row? For example: Bruce Willis - The Six Sense - Die Hard - Mercury Rising I'm really new to SQL and am having trouble grasping whether this is something that's possible. So far my results have been looking like Bruce WIllis - The Sixth Sense Bruce Willis - Die Hard Bruce Willis - Mercury Rising Thanks in advance, sorry for such an elementary question. E: God damnit let me fix the formatting on that. Good Will Punting fucked around with this message at 20:15 on Apr 7, 2012 |
# ? Apr 7, 2012 20:13 |
|
Good Will Punting posted:Movies table: MovieID, Movie If you are using MySQL you can use the GROUP_CONCAT function. This is not part of standard SQL and doesn't necessarily have equivalents in other RDBMSs, so if you are using another RDBMS it may be more complicated. Maybe in other RDBMS it can be expressed as a trivial case of using pivot tables? nb. The movie names will all be in one column, not each in their own column. Something like the following code:
|
# ? Apr 8, 2012 01:12 |
|
Thanks for the answer. GROUP_CONCAT is exactly what I'm looking for. Unfortunately, I'm doing this in SQL Server (school project) so I'm looking at work-arounds now. GROUP_CONCAT is really cool though, and I had never heard of it before your reply, so thanks for that!
|
# ? Apr 8, 2012 01:16 |
Hammerite posted:... You're right about the querying -- I'd like to be able to do statistical analyses on the dictionary and its contents once its filled up a bit. However I'm not entirely sure about the format you're suggesting here, are you saying that there is a 1:1 duplication of the contents of Word and WordVersion, except that WordVersion has the potential for supplementary rows with extra info? Forget the Latin, I'll give an example that'll stand on its own: code:
I'm seeing a few problems/oddities with that idea so I'm sure I'm misunderstanding you.. My issue is then, with splitting the info into multiple rows/tables, wouldn't it make the database quite inefficient, that the script has to do a SELECT * WHERE query through multiple tables and multiple rows every time I query anything, just to make sure I'm getting all the info, when 90% of the time there won't be multiple rows? Or should I add to the original row in 'Word' a binary flag saying 'Multiple', which the script gets and then if it's true, does a further search for supplementary values?
|
|
# ? Apr 8, 2012 02:53 |
|
Sulla-Marius 88 posted:You're right about the querying -- I'd like to be able to do statistical analyses on the dictionary and its contents once its filled up a bit. I'm not sure what the best way is of going about it, but duplicating data isn't a good idea. Thinking about it again, I am wondering what the primary key of the Word table is. Would it be the first column, the Nominative Singular or what have you? Then again I do not know whether the Nominative Singular of a word never has variations. I see no reason for it to be so. So I doubt it is a good primary key. Then again, there are two other things I don't know: is there always a "preferred" variant for each form of the word, a default variant? And do the variants in each form of the word correspond to one another? i.e. if a speaker uses variant no. 2 of the "dative plural" then can they be expected to use variant no. 2 of the "vocative plural"? Presumably not, since in the example word you linked, the "vocative singular" has a different number of variants to the "vocative plural" (and neither is equal to 1). This being the case, I don't see the case for having a table with 12 columns and filling rows with column-values that don't relate to one another. (That is, putting 'dive' in putative column VocativeSingular and in the same row putting 'di' in column VocativePlural - despite the fact that these two variants do not directly relate to one another.) I am thinking of a solution that looks something like this: (Perhaps I am going OTT on tables, and the Singular/Plural and Cases would be better hard-coded. You will have to decide that.) code:
edit: The forum ate my copy-pasted accented characters from the Wiktionary page.
|
# ? Apr 8, 2012 05:18 |
That's actually a very elegant and clever solution. There is no guarantee that any instance of a word (for e.g. deum, the nom. sg. of the word) is unique and could not be replicated in another word -- you'd be able to figure out the meaning based on context and usage, so there is chance for a double up of words in the table, so having an incremental numeric semi-unique ID is the best solution -- as you've done, "1, 1, 1, 1, deus". It also opens up the possibility of just adding a supplementary column to the WordVersion table if I want to add references to more information, such as etymology or anything like that -- it can just be empty for most words, but where extra info exists, it can have a pointer to a separate table with that info. I'm going to whack that in now and see how it goes, thanks a lot Edit: I'd be best off making the 'Word' column itself the only index in all that, right? Because I'll need to do look-ups for a specific word and then I can grab all the entries with that same ID. Editx2: In fact, I don't need the foreign keys or those two other tables at all, do I? They're just there to ensure structural conformity and clarify the definitions, but since I'm the only one who will be dealing with this database or the code, I can make do with just the WordVersion table, no foreign key references, and just ensure I have a good commenting/documentation system so I understand what the '1, 1, 2, 1' means.. Sulla Faex fucked around with this message at 09:42 on Apr 8, 2012 |
|
# ? Apr 8, 2012 09:00 |
|
EDIT: Got it, see bottom I can't figure out where my query is going wrong. I feel like I'm missing something stupid. code:
Error: #1054 - Unknown column 'c.id' in 'on clause' Here are the relevant table structures: code:
dlp_item and dlp_battleStats are basically echos of those two tables, but they're for specific game instances. So I'm trying to get a query that would give me all the current as well as static stats (and battle stats, if they exist) given an item id. EDIT: Turns out I haven't done much mysql 5 programming. It's a little more fussy about joins. Fixed code is: code:
Gilgamesh fucked around with this message at 15:51 on Apr 8, 2012 |
# ? Apr 8, 2012 15:30 |
|
Bumping this question again because I have to think there's a way around this, right?quote:We have our main MySQL server in Wisconsin. We have the bulk of our customer service staff in Iowa. The CS staff is complaining that the connection is too slow to the server, which makes sense - the queries are hefty and the page is overlarge. Both of these can be remedied, but there's also wondering if we could change our MySQL topology. The options seem to be: We already replicate from the master in Wisconsin to a slave in Iowa, but the staff need full read/write access to the data, so that's not a huge boon. Master-Master setups are apparently difficult to pull off in MySQL? Any ideas?
|
# ? Apr 9, 2012 14:39 |
|
When attempting to set the cascade action to Set Null for both these associations, SQL Server 2008 R2 says Unable to create relationship 'FK_Cars_Drivers_Secondary'. Introducing FOREIGN KEY constraint 'FK_Cars_Drivers_Secondary' on table 'Cars' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. I've read but don't quite understand http://stackoverflow.com/questions/851625/foreign-key-constraint-may-cause-cycles-or-multiple-cascade-paths I don't see any cycles here, so it must be a "multiple cascade path". If a Driver is deleted, what harm is setting PrimaryDriverId and SecondaryDriverId to null?
|
# ? Apr 9, 2012 18:56 |
|
I have a non-technical database question. I work for a small company with 10 employees, looking to hire an 11th. We do marketing and analytical consulting for non-profits and are looking for an entry level person with some experience using SQL Server to work on some basic ETL stuff and pulling together some custom datasets in response to ad hoc client requests. I didn't anticipate having a hard time finding this person to be honest, but we've gone a month with only one promising lead. So my questions is, where do you guys typically look for new hires/where do you advertise the position? Most places people point me are mostly geared toward application developers/web developers. Where can I find recent MIS grads or even people with an Econ or stats degree who know how to write some SQL?
|
# ? Apr 9, 2012 19:53 |
|
I don't understand. Are you only finding developers who are bad at databases for some reason? That data retrieval you described can certainly turn into a full-time development type of thing depending on how your database is laid out, what new stuff you add to it, and how fickle your clients are. I've worked with a "data analyst" before and now I would certainly not deal with anyone who claimed to understand databases and SQL without knowing the rest of the story on contemporary business programming. But to answer your question, I always use Craigslist and it works fine. The trouble you'll find anywhere is that 3/4 resumes drastically overstate people's abilities and the only way to tell is to bring them in for an interview.
|
# ? Apr 9, 2012 20:40 |
|
We're finding application developers who will be absolutely bored to tears in this job. We need the "data analyst" who wants to spend most of their time writing SQL at the start and transition into cube development/maintenance and more BI-type stuff. Instead, we're getting either liberal arts people with 0 technical skills, or people who list experience with C#, Java, C++, etc. And hey, that would be great! But they go on to talk about all of the cool applications they have developed/want to develop. That's not what we do. Thanks for the suggestion though, we were waiting to post on Craigslist but I guess we might as well!
|
# ? Apr 9, 2012 21:00 |
|
Is a "link table" the only way to handle a many-to-many relationship? I'm creating a database to keep track of job title <--> active directory group membership information and that's obviously many-to-many. I'm also a bit stuck on how to process the information I have available to get it into the database. Presently, it resides in a crappy Excel workbook. It is easily exported, but the relationships are another matter. Right now the Excel workbook keeps track of those by using a hidden sheet that has a column for each job title, and then each group that is associated with that title is listed under that column (with the title itself at the top). I'm planning to go from Excel 2007 to Access 2007...it's what I have available and I have some experience with Access, so whatever. Any ideas?
|
# ? Apr 10, 2012 23:15 |
|
Powdered Toast Man posted:Is a "link table" the only way to handle a many-to-many relationship? I'm creating a database to keep track of job title <--> active directory group membership information and that's obviously many-to-many. It may not be the only way, but it's the best way. They are also known as a "join tables". Also it's a good for storing meta data on the relationship itself in that table, such as when it was created, who it was created by, etc.
|
# ? Apr 10, 2012 23:45 |
|
I have two tables, both which have lists of dates something like this: Table1 has multiple days in a row Jan.1 Jan.2 Jan.3 . . . The second table just has random days that jump around Jan.5 Jan.12 Jan.18 . . . I'm trying to join the tables by closest date after the date in table1. So the output would be something like this T1Date T2Date Jan1 Jan5 Jan2 Jan5 Jan3 Jan5 Jan4 Jan5 Jan5 Jan5 Jan6 Jan12 . . . Jan12 Jan12 Jan13 Jan18 . . . etc. My code is something like code:
quote:Day Day My guess is that this line code:
is only running once and isn't updating every time SQL goes over to the next date. So it starts at 05/05/2011 and selects 05/07/2011 for the second column. However, when it gets to 05/09/2011, the line of code isn't rerunning and so it doesn't select 05/09/2011 for the second column. edit in response to below post: The line with the two ambiguous D's: WHERE DATEDIFF(D,t1.D,t2.D) >= 0 ORDER BY DATEDIFF(D,t1.D,t2.D))) Those two ambiguous D's aren't actually variables, but just telling SQL to subtract and add by days. I'll rename the D's into "Day" so they're less confusing. zyang31 fucked around with this message at 15:17 on Apr 11, 2012 |
# ? Apr 11, 2012 04:34 |
|
zyang31 posted:Unfortunately, it's not working and I'm not exactly sure why What does "it's not working" mean? Does it give an error message? Does it do something without complaining, but yield the wrong results? Your last query refers to columns called D a lot. In some places you have specified the table but in others you have not, for example DATEADD(D,DATEDIFF(D,t1.D,t2.D) contains two D's which are ambiguous because it's not clear what table they are from.
|
# ? Apr 11, 2012 11:05 |
|
What do you do when a customer wants your web app database encrypted (to meet HIPAA standards) when you don't even store HIPAA data? It's a big enough account where it makes more sense to just do what they want instead of arguing with them about how it's bullshit. Option 1 is not giving Rackspace access to our servers. Which would be fine except that's the whole point of having managed servers. Option 2 is 'encrypting the database'. I proposed keeping the mySQL database on an encrypted partition on the server (CentOS), but they want it so someone can't do a 'select *' and just get a huge dump of all the data. We keep the data for multiple websites on the same server, and each website can only access the database for that server, but we don't have access whittled down per customer. So even though our web app only returns data for your employees if you run a report, there's nothing in the DB preventing that. Rackspace offers this but I don't know if that's what we want: http://www.rackspace.com/cloud/tools/applications/gazzang-ezncrypt/
|
# ? Apr 11, 2012 16:18 |
|
zyang31 posted:I have two tables, both which have lists of dates something like this: This correlated subquery works though. code:
|
# ? Apr 11, 2012 16:41 |
|
Hammerite posted:What does "it's not working" mean? Does it give an error message? Does it do something without complaining, but yield the wrong results? EDIT: Oh, zyang31 already responded to that. Jethro fucked around with this message at 17:21 on Apr 11, 2012 |
# ? Apr 11, 2012 17:08 |
|
What would be the syntactically correct way to write this: SELECT * FROM atable WHERE (open_date BETWEEN '2012-01%' AND '2012-02%') EDIT: got it. SELECT * FROM atable WHERE (open_date >= '2012-01%' AND open_date <= '2012-02%') revmoo fucked around with this message at 17:38 on Apr 11, 2012 |
# ? Apr 11, 2012 17:36 |
|
Bob Morales posted:What do you do when a customer wants your web app database encrypted (to meet HIPAA standards) when you don't even store HIPAA data? HIPAA doesn't require encryption of the database - it's sufficent to implement SSL if you have a web facing service.
|
# ? Apr 11, 2012 23:57 |
|
revmoo posted:What would be the syntactically correct way to write this: Could you just do select * from atable where open_date >= '2012-01-01' and open_date < '2012-03-01' This seems a bit more clear, if it accomplishes the same thing.
|
# ? Apr 12, 2012 19:17 |
|
|
# ? May 14, 2024 22:08 |
|
hieronymus posted:HIPAA doesn't require encryption of the database - it's sufficent to implement SSL if you have a web facing service. There's different levels involved, though I went through a similar go-round with PCI compliance and encryption. Luckily for PCI if you simply don't store things you shouldn't be storing anyway (e.g. CCN, CVV, DOB) you can get away with writing the other PIN stuff (fname, lname, address1, etc.) to db if you're always using SSL when collecting/communicating. Not sure if HIPAA gives you that kind of out though. Don't know how much you've talked to your Rackspace guy but they were somewhat helpful on the documentation side. Their bona fides from the various certification agencies are legit, not sure if that'll help. I had to collect information about how they restrict access to the servers, have 24 hour video recordings of the racks, biometric pre-scheduled access only, etc.
|
# ? Apr 13, 2012 03:11 |