SQL Help Required
-
Hi, I need to retreive some info from an SQL2005 db, but am not knowledgeable in SQL to work out an efficient statement. Your help will be greatly appreciated. I need to retreive data for a given user(db_User) whilst counting info from a second column(db_Hours). However to make things a bit more difficult id like to count/sum all the (db_Hours) values as two named fields. The values of these named fields will be grouped according to a 3rd column(db_Valid) will either be 'yes', 'edit' or 'no'. SO in other words id like one statement (if possible) that will get me all the values of (db_Hours) for a named user, as two variables. One being the sume of all the 'db_Hours' where 'db_Valid' is equal to "yes", and a second where 'db_Valid' is not equal to 'yes'. I hope this makes sense, and that some kind person is able to help me out. Many Thanks guys! :sigh:
-
Hi, I need to retreive some info from an SQL2005 db, but am not knowledgeable in SQL to work out an efficient statement. Your help will be greatly appreciated. I need to retreive data for a given user(db_User) whilst counting info from a second column(db_Hours). However to make things a bit more difficult id like to count/sum all the (db_Hours) values as two named fields. The values of these named fields will be grouped according to a 3rd column(db_Valid) will either be 'yes', 'edit' or 'no'. SO in other words id like one statement (if possible) that will get me all the values of (db_Hours) for a named user, as two variables. One being the sume of all the 'db_Hours' where 'db_Valid' is equal to "yes", and a second where 'db_Valid' is not equal to 'yes'. I hope this makes sense, and that some kind person is able to help me out. Many Thanks guys! :sigh:
Why don't you give a sample of the tables you are trying to pull from and the relevant fields that are in those tables. I'm guessing you are going to have a statemnet that will include a Group By clause and Sum function, but we can't create it for you without specifics. It may end up to be something like this:
SELECT User, Valid, SUM(Hours) FROM MyTableName GROUP BY User, Valid