SQL Question About Selecting Values Dependent On Another Column
I have a table with one row for each test a user has taken, with columns for userid, score, and test date. I have a query that gets the highest score and the date of the latest test for each user. Easy. But how can I also get the score achieved on the latest test for each agent?
Thanks,
John
(By the way, I've been looking for a good SQL mailing list to ask this question and have been unsuccessful. If there's a better forum than this for this type of question, please let me know).
View Complete Forum Thread with Replies
Sponsored Links:
Related Messages:
Inserting Values Into A Column By Selecting Value From Different Table
Hi, I have a question regarding how to insert one column values into a table by selecting from different table..Here is the syntax.. ------------ insert into propertytable values (select lastvalue+incrementby from agilesequences where name='SEQPROPERTYTABLE', 13926, 0, 4, 1, 451, 1, 8, 1) the first column in the propertytable will be... select lastvalue+incrementby from agilesequences where name='SEQPROPERTYTABLE' How do I do that..Help PLZ..
View Replies !
View Related
Hyper Link Dependent On A Column
Excuse my illiteracy in this subject, I just learned about this yesterday, I managed to create a report by using business intelligence report wizard, and when I preview it seems that I can view the fields that I wanted to view. But in addition to that I also want to add hyperlinks to some of the fields, because I am planning to embed the whole report in a web page. For example if I go on the field that I want to add hyperlink and right click->properties->navigation tab->Jump to url, I thought that I can handle it. Actuall it works fine if I link it to http://www.microsoft.com but let's assum e the name of the field is ID, and you want to link to http://somewebsite/somepage.aspx?id= (id in that cell), how can I achieve this parametric behavior, actually I tried right click cell->properties->navigation tab->Jump to url, and filled url text box http://somewebsite/somepage.aspx?id=&(concatenation operator)=Fields!ID.Value but what happens is instead of evaluating the value of ID field, it takes expression as text as text and that's why it links to totally wrong url. Is there a way to get around this problem. And can somebody suggest me a detailed tutorial on programmatically using reports in .net web applications using c#. If somebody can help me I'd be really glad. Erinc
View Replies !
View Related
Selecting Values In CSV
I have to write a master detail query, in which the detail record shouldbe stored in a variable as Comma Seperated Values. Can anyone helpme......Sun*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!
View Replies !
View Related
Selecting Null Values
I have a stored procedure that allows users to select addresses based on partially supplied information from the user. My procedure seems to work fine in all but a few cases. If a user decides to select all the rows for a particular country the procedure below does not return any rows even if the rows exist. I tracked this down to the fact that for Non US countries I set both the StateCode and Country Code to nulls. . Below is a partial version of my code. Can anyone show me how I can do a "Like" Search even if some of the fields in the row contain null values? Thanks 1 CREATE PROCEDURE dbo.Addresses_Like( @SendTo VarChar(50) = Null 2 , @AddressLine1 VarChar(50) = Null 3 , @AddressLine2 VarChar(50) = Null 4 , @City VarChar(50) = Null 5 , @StateCode VarChar(2) = Null 6 , @ZipCode VarChar(10) = Null 7 , @CountryCode VarChar(2) = Null) 8 9 10 Declare @SearchSendTo VarChar(50) 11 Declare @SearchAddressLine1 VarChar(50) 12 Declare @SearchAddressLine2 VarChar(50) 13 Declare @SearchCity VarChar(50) 14 Declare @SearchStateCode VarChar(2) 15 Declare @SearchZipCode VarChar(10) 16 Declare @SearchCountryCode VarChar(2) 17 18 If (@SendTo Is Null) 19 Set @SearchSendTo = "" 20 Else 21 Set @SearchSendTo = @SendTo 22 23 If (@AddressLine1 Is Null) 24 Set @SearchAddressLine1 = "" 25 Else 26 Set @SearchAddressLine1 = @AddressLine1 27 28 If (@AddressLine2 Is Null) 29 Set @SearchAddressLine2 = "" 30 Else 31 Set @SearchAddressLine2 = @AddressLine2 32 33 If (@City Is Null) 34 Set @SearchCity = "" 35 Else 36 Set @SearchCity = @City 37 38 If (@StateCode Is Null) 39 Set @SearchStateCode = "" 40 Else 41 Set @SearchStateCode = @StateCode 42 43 If (@ZipCode Is Null) 44 Set @SearchZipCode = "" 45 Else 46 Set @SearchZipCode = @ZipCode 47 48 If (@CountryCode Is Null) 49 Set @SearchCountryCode = "" 50 Else 51 Set @SearchCountryCode = @CountryCode 52 53 54 Select AddressID 55 , SendTo 56 , AddressLine1 57 , AddressLine2 58 , City 59 , StateCode 60 , ZipCode 61 , CountryCode 62 , RowVersion 63 , LastChangedDateTime 64 , OperID 65 From Addresses 66 Where SendTo Like RTrim(LTrim(@SearchSendTo)) + "%" 67 And AddressLine1 Like RTrim(LTrim(@SearchAddressLine1)) + "%" 68 And AddressLine2 Like RTrim(LTrim(@SearchAddressLine2)) + "%" 69 And City Like RTrim(LTrim(@SearchCity)) + "%" 70 And StateCode Like RTrim(LTrim(@SearchStateCode)) + "%" 71 And ZipCode Like RTrim(LTrim(@SearchZipCode)) + "%" 72 And CountryCode Like RTrim(LTrim(@SearchCountryCode)) + "%" 73 Order By CountryCode, City, AddressLine1, AddressLine2, SendTo
View Replies !
View Related
Updating The Values While Selecting
SELECT #followups.suspectid, #followups.planid, cond4, cond5, cond6, cond7, cond8, tbpdmmembers.firstname tbpdmmembers_firstname, dbo.GetMemID_PartC_D(#followups.hic,#followups.IsPart_C) tbpdmmembers_MemberID, --tbpdmmembers.Plan1 tbpdmmembers_MemberID, tbaddress.address1 tbaddress_address1, tbaddress.address2 tbaddress_address2, tbaddress.city tbaddress_city, tbaddress.state tbaddress_state, tbaddress.zip tbaddress_zip from #followups I want to check if the tbaddress.address1 tbaddress_address1 if it is =null or empty then make it = tbaddress.address2 tbaddress_address2, at the same time I make the tbaddress.address2 tbaddress_address2, null. Otherwise leave it as it is. Actually, I am working with the report and the tbaddress.address1 carrying the apt number. if there is no aprt # then the line print blanks. so that brings the empty line between the street address and the citystate line. That is what i am tryig to cover. There could be a way to do this from the crystal report but I am thinking of doing this way cause I can't get the solution to do it from the crystal report.
View Replies !
View Related
Selecting Multiple Values From One Table
I have a sql select query that I'm pulling from a "Years" table to link to 3 columns in an Items table.ZCValuesYear table has two colums: YearID and YearYearID Year1 20042 20053 20064 20075 2008...I want to bind the "Year" value to the three colums in the ZCItem table: ItemUseFirstYearID ItemUseLastYearID ItemYearIDThe query below will pull all the "ID's" for each of the colums, but how would I make it pull the "Year" value (instead of record 4, it would pull 2007 instead)?<asp:SqlDataSource ID="sqlItemSelect" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnString %>" SelectCommand="SELECT ZCPartVault.PartVaultID, ZCPartVault.PartVaultItemID, ZCValuesYear.Year, ZCItem.ItemName, ZCItem.ItemUseFirstYearID, ZCItem.ItemUseLastYearID FROM ZCPartVault FULL OUTER JOIN ZCItem ON ZCPartVault.PartVaultItemID = ZCItem.ItemID FULL OUTER JOIN ZCValuesYear ON ZCItem.ItemUseLastYearID = ZCValuesYear.YearID AND ZCItem.ItemUseFirstYearID = ZCValuesYear.YearID AND ZCItem.ItemYearID = ZCValuesYear.YearID" > </asp:SqlDataSource>
View Replies !
View Related
Selecting Data Wheere Values Contain Something
Hi,I have a message system, where people insert their message to the database, and others pick up their messages by selecting messages that have their username as the reciever ID.I have just intoduced bulk message sending - sending to multiple users. This requires many usernames being entered into the recievername column, seperated by a comma.Is there a way to select messages if the column name contains their username, rather than is their username? Because there may be more than one name, I would like everyone that has their name in the column to be able to retrieve the message, even if they arent the only reciever..Please ask if more explanation is needed!Thanks,Jon
View Replies !
View Related
Selecting The Two Biggest Values Of A Field
I need to do a SQL query based on the two biggest values of a field. PLS , what s the SQL syntax : select * from Table where PRICE ......Ex: if the values of the field PRICE are : 50, 40, 100, 30 and 150.The request should select the rows that have Price equal 100 or 120Thanks a lot for help
View Replies !
View Related
Help With Joining/selecting Values To Show
I am editing a pre-existing view.This view is already bringing data from 40+ tables so I am to modify itwithout screwing with anything else that is already in there.I need to (left) join it with a new table that lists deposits and thedates they are due. What I need is to print, for each record in theview, the due date for the next deposit due and the total of allpayments that they will have made by the next due date.So this is how things are. I join the table and it obviously bringsmultiple records for each record (one for each matching one in the newtable). I need, instead, to be able to make out what due date I shouldprint (the first one that is GETDATE()?) and the total of deposits upto that date.Now, payments can be either dollar amounts or percentages of anotheramount in the view. So if it's an amount I add it, if it's a % Icalculate the amount and add it.Example:for group X of clients...Deposit 1 due on oct 1: $20Deposit 2 due on oct 15: $30Deposit 3 due on nov 15: $40Deposit 4 due on nov 30: $50for group Y of clients...Deposit 1 due on Oct 30: $200Deposit 2 due on Nov 30: $300Deposit 3 due on Dec 30: $400So when if I execute the view today (Nov 7th) each client from group Xshould have:Next Due Date: nov 15. Total: $90 (deposit 1 + deposit 2 + deposit 3)Group Y should have:Next Due Date: Nov 30, total: $500 (Deposit 1 + deposit 2)And so on.
View Replies !
View Related
Selecting The Two Biggest Values Of A Field
I need to do a SQL query based on the two biggest values of a field. PLS , what s the SQL syntax : select * from Table where PRICE ...... Ex: if the values of the field PRICE are : 50, 40, 100, 30 and 150. The request should select the rows that have Price equal 100 or 120 Thanks a lot for help
View Replies !
View Related
Selecting From Table And Adding Ur Own Values
Hey all This is probably the wrong category to post my question in. Apologies if it is. I have got a Data Flow Task that has an OLE DB Source and a Flat file destination. Is there a way to do the following: SELECT id,'31809','C:LCImportDataImages' & id & '.jpg', '1' FROM table1 This obviously doesn't work but I want to insert the id from the table, followed by the value '31809', followed by 'C:LCImportDataImagesid.jpg', followed by '1' So, the id in 'C:LCImportDataImagesid.jpg' is the same as the id from the table. I want the file to look like: 1, 31809, C:LCImportDataImages1.jpg, 1 2, 31809, C:LCImportDataImages2.jpg, 1 5, 31809, C:LCImportDataImages5.jpg, 1 etc... I would really appreciate it if someone could point me to the right direction. I am trying to work on it..will put up a solution if I find one myself. Many thanks, Rupa
View Replies !
View Related
Selecting And Placing Values From Sql Query Into Textboxes
Hi. I have an sql query that i use to insert articles to a sql databse table and for that i use addWithValue to select witch textboxes etc goes where in the database. Now i need to retrive these values and place them back into some other textboxes (some of them multiline) ,and i wonder if there are any similar ways to retrive values like AddWithparameter so i can easily do textBox.text = //whatever goes here ?
View Replies !
View Related
Selecting Null Values? Mssql 2005
Hi, i have something like this: SELECT a.boardname, a.description, a.threadcount, a.answercount, a.lastthreadid, b.username, b.subject, b.created FROM forum_board AS a, forum_topics AS b WHERE (a.forumid = @ID) AND (b.id = a.lastthreadid) The problem here is that lastthreadid does not always have a post linked to it, so sometimes its null. I want it to still return all the boards and then just returnnull values or "" in b.username, b.subject, b.createdThis returns nothing. How can i force it to select these values?
View Replies !
View Related
Selecting Where Cloumn = Column OR Column = Value
Hi I have a gridview with a sql data source and a few drop down lists where i choose values to sorth what i would like to retrive from the table. The problem im facing is that when i pass values to the database, i can sort out and retrive my items when both my listboxes have selected values. But when i want to select everything from the table where the column = clumn or cloumn = value i dont get anything back. I have 2 dropdown lists. One for category and one for location. These are populated drom the database by selecting the column and retriving destinct values. I have a function that fires when one of the dropdown lists are changed witch changes the sql datasource select value so it retrives items sorted by the selected categories and locations. Here is the function: protected void DropDownList_Change(object sender, EventArgs e) { string Category = DropDownListKategori.SelectedValue.ToString(); string Location = DropDownListEtabl.SelectedValue.ToString(); SqlDataSource1.SelectCommand = "SELECT ARTNR, ARTTYP, AKTIVITET, DATUM, KUND, PLATS, KOMMENTAR FROM ARTIKEL WHERE ARTTYP = @ARTTYP AND PLATS = @PLATS"; SqlDataSource1.SelectParameters.Clear(); SqlDataSource1.SelectParameters.Add(@"ARTTYP", Category); SqlDataSource1.SelectParameters.Add(@"PLATS", Location); SqlDataSource1.DataBind(); } The dropdown lists have an option to not retrive values by category or location. I have set that value to PLATS and ARTTYP thinking the query would would retrive everything if these were selected SELECT ARTNR, ARTTYP, AKTIVITET, DATUM, KUND, PLATS, KOMMENTAR FROM ARTIKEL WHERE ARTTYP = ARTTYP AND PLATS = PLATS however if both these drop down lists are set to not filter, my query gets nothing in return. And if one of the lists has this selected and ther other one has a value, say a location or something nothing is retrived either. However if both columns have something selected i do get values returned. My speculation is that the query beeing run when this happens is that it is trying to find columns having the value ARTTYP or PLATS (category or location), as a string and actually seeing it as Im trying to retrive values where column = column. Any suggestions on how i can make my query run as intended or is there another problem Im not seeing.
View Replies !
View Related
Selecting Numeric Or Time-scale Values On Chart Yields Duplicate Months
I have a line chart which works great except when the x axis displays duplicate months. I have tried format codes of MM-YYYY and MMM and have the "numeric or time-scale values" checkbox checked. The data displays fine but the X axis in the case of the MMM format code displays as: Sep Oct Oct Nov Nov leaving the user to wonder where exactly does October and November start... I've googled around but don't see off-hand what I am doing wrong. I am display 3 simultaneous lines if that matters... Thanks! Craig
View Replies !
View Related
Selecting The Same Column Twice In The Same Where Clause
Hi :From a crystal report i get a list of employee firstnames as a stringinto my store procedure. Why is it comming this way ? hmmmmmm it's aquestion for me too.ex: "e1,e2,e3"here are my tablestblProjectsProjectId123tblEmployeeemployeeId FirstName1 e12 e23 e3tblProjectsToEmployeeProjectId employeeId1 11 21 32 12 23 13 23 34 14 3i need to find out the project ids all 3 of these employees worked on.so the out put i need isprojectId13How can i get it ????????????now i can use replace command to format it to a OR clause or ANDclauseSET @string= 'employeeId =' + '''' + REPLACE('e1,e2,e3',',',''' ORemployeeId = ''') + ''''some thing like this.OR clause will give me all 4 projects.in('e1','e2','e3') will give me all 4 projects.of cause AND command will not give me any.other method i tried was adding the employee table 3 times into thesame SQL string and doing some thing likeWHERE (empTable1.Firstname ='e1' AND (empTable1.Firstnamein('e2','e3'))AND (empTable2.Firstname ='e2' AND (empTable1.Firstname in('e1','e3'))AND ...and goes alone. this gives me some what i needed. but it's a verymessy way of doing it, because i get a comma seperated stringparameter i have to construct the sql string on the fly.any help or direction on this matter would greatly appreciated.thankseric
View Replies !
View Related
Selecting Only Rows That Same The Value In One Column
Mike writes "Hi, I am a beginner with TSQL and I hope this is not a silly question :-) Lets say I have a table with 2 columns, 1 a primary key identity field with increment 1 and the other a char. EG: ID ANIMAL --------- 1 CAT 2 DOG 3 PIG 4 RAT 5 PIG 6 DOG 7 DOG . . And so on with many entries How do I return a selection of rows that have the contents of the ANIMAL field matching 1 or more times EG: From above table I want to return rows 2,6 & 7 and 3 & 5 ONLY and not 1(CAT) and 4(RAT) because they only occur once. In my real life situation I have unknown numeric data in field 2 but the principal is the same. How do I do this? Thanks in Advance Mike"
View Replies !
View Related
Selecting Single Sorted Row From Many Column
HiBeen at this for 2 days now.Each business has several packages which they can sort usingsort_order.I'm trying to get one package for each business(that I can do), howeverI want it to be the one with the lowest sort_order valueAs you can see below the first record has sort_order=5 when it shouldbe 1.Most of the sort_order columns will be zero by defaultAny help so i can get on with my life!CheersGary------------Current select-------------------SELECT *FROM dbo.testAccommodation_Packages T1WHERE (NOT EXISTS(SELECT *FROM testAccommodation_PackagesWHERE business_id = T1.business_id AND Package_ID < T1.Package_ID))--------------results:-----------------------Package_IDbusiness_iditem_namesort_order123rd Night FREE ...5113Donegal Town ... 0204Executive ...0--------------To recreate----------------------CREATE TABLE [testAccommodation_Packages] ([Package_ID] [int] IDENTITY (1, 1) NOT NULL ,[business_id] [int] NULL ,[Item_Name] [nvarchar] (300) NOT NULL ,[sort_order] [int] NULL CONSTRAINT[DF_Accommodation_Packages_sort_order] DEFAULT (0),)-------------------------------------------------INSERTtestAccommodation_Packages(Package_ID,business_id, Item_Name,sort_order)VALUES('1','2','3rd Night FREE when you stay 2 nights MIDWEEK (129 EuroPPS)','5')INSERTtestAccommodation_Packages(Package_ID,business_id, Item_Name,sort_order)VALUES('2','2','Selected Donegal Town Hotel Weekend Sale - 2 B&B and 1Dinner Only € 129 PPS','4')INSERTtestAccommodation_Packages(Package_ID,business_id, Item_Name,sort_order)VALUES('3','2','2 Night Specials -Jan, Feb & Mar 2 B&B and 1 Dinner 149Euro PPS','3')INSERTtestAccommodation_Packages(Package_ID,business_id, Item_Name,sort_order)VALUES('4','2','Easter Hotel Breaks in Donegal Town - 2 B&B + 1 D€169pps','2')INSERTtestAccommodation_Packages(Package_ID,business_id, Item_Name,sort_order)VALUES('5','2','2005 Bluestack Hillwalking, 2 nights B&B, 1 Dinner, 5course Lunch 159 Euros PPS (~109 Stg)','1')INSERTtestAccommodation_Packages(Package_ID,business_id, Item_Name,sort_order)VALUES('6','2','April Pamper Package - 2 Night Special ONLY€195pps','10')INSERTtestAccommodation_Packages(Package_ID,business_id, Item_Name,sort_order)VALUES('7','2','Discount Hotel Prices for 8th & 9th April Only € 119PPS','7')INSERTtestAccommodation_Packages(Package_ID,business_id, Item_Name,sort_order)VALUES('8','2','Golden Year Breaks in Donegal - 4B&B + 2 Dinner€229pps','8')INSERTtestAccommodation_Packages(Package_ID,business_id, Item_Name,sort_order)VALUES('9','2','Hotel Summer Breaks Sale in Donegal - 2B&B + 1 Dinner€169pps','9')INSERTtestAccommodation_Packages(Package_ID,business_id, Item_Name,sort_order)VALUES('10','2','STAY SUNDAY NIGHTS FOR €25PPS','6')INSERTtestAccommodation_Packages(Package_ID,business_id, Item_Name,sort_order)VALUES('11','3','Donegal Town Midweek Special 99 Euro PPS 3 Nights B&B','0')INSERTtestAccommodation_Packages(Package_ID,business_id, Item_Name,sort_order)VALUES('12','3','Bridge Weekend 2 nights B&B 79 Euro PPS (approx 55Stg) Double Room','0')INSERTtestAccommodation_Packages(Package_ID,business_id, Item_Name,sort_order)VALUES('13','3','Donegal Spring Weekend Specials 2 B&B 1 Dinner109.00euros pps','0')INSERTtestAccommodation_Packages(Package_ID,business_id, Item_Name,sort_order)VALUES('14','3','Valentines Weekend 2 nights B&B and 1 four coursegourmet dinner 99Euro PPS','0')INSERTtestAccommodation_Packages(Package_ID,business_id, Item_Name,sort_order)VALUES('19','3','Golden Years Break.40% OFF 4 nights B&B€129.00p.p.s.','0')INSERTtestAccommodation_Packages(Package_ID,business_id, Item_Name,sort_order)VALUES('20','4','Executive Celebration Offer 1 night B&B + Dinner €139 PPS','0')INSERTtestAccommodation_Packages(Package_ID,business_id, Item_Name,sort_order)VALUES('21','4','Watercolour Painting Break 3 B&B Full Board andTuition € 335 PPS','0')
View Replies !
View Related
Selecting A Column From Multiple Tables
Hello, Is it possible to get a list of rows from Multiple tables which have the same Column Name. I have 3 tables which comtain similar info and I want to get a list of Names the structure is ID;Name;Address;Phone No. I was thinking something along the lines of SELECT Name FROM TABLE1,TABLE2, TABLE3 But this does not work. Is there a nice way of doing this with SQL or should I do code outside the SQL DB
View Replies !
View Related
Selecting Multiple Column From Sub Query.
Hi, I am having two tables Products and Transaction In products I have ProductID and Description. (10 Records) In Transaction I have ProductID, Lot, Quantity and ListID . ( 4 Million Records) When I use the inner join between these tables as below query its taking lot of time to give output. select ProductID, Desc, Lot, qty from Products inner join Transactions on Products.ProductID = Transactions.ProductID where ListID = '9090909' otherwise, if I use the below query its takes very few milli seconds to give output but I am not able to get the description from the product table. select * from Transactions TR where TR.ListID= '9090909' and TR.ProductID in (select NDC from Products where Products.ProductID = TR.ProductID) Any from can help me to get the description too at very few times. Regards,
View Replies !
View Related
Selecting The Column Description In 2005
I am migrating between SQL Server 2000 and SQL Server 2005 but hit a snag when attempting to write a query to display the column's description. I used this code with SQL Server 2000 to get the "Description" data. select o.name 'table' , c.name 'column' , p.value as 'description' , t.name 'datatype' , c.isnullable 'nullable?' , c.length, m.text 'default_text' from sysobjects o join syscolumns c on o.id = c.id join sysproperties p on o.id = p.id and p.smallid = c.colid join systypes t on c.xtype = t.xtype left outer join syscomments m on m.id = c.cdefault order by 'table' , 'column' How can I reproduce this with SQL Server 2005? I tried using the following which gives me a lot of the same data but not "Description": SELECT * FROM INFORMATION_SCHEMA.COLUMNS Any help here would be greatly appreciated.
View Replies !
View Related
Selecting Relative Record Number As A Column Value
Hello I am in the process of learning Visual Basic, unfortunately I am learning by the seat of my pants on a very hot project with no prior training. I have an SQL that I need to reproduce in Visual Basic and I am having an issue. The script seems to work well as long as I do not select the Relative Recod Number of a file as a column value. The problem is however I need that value for a match to another file. Records in File A have a match in file B but the next record down is the record I need. So what I am doing is matching File A to File B on a common field which returns the Relative Record Number of the record in File B. I am then doing a sub selection on File B selecting Relative Record Number as a column value. I match the Relative Record Number + 1 from File B to the Relative Record Number of the SubQuery to retrieve my desired value. Can anyone tell me what I need to use in place of RRN on the SubQuery so the selection will work. I have included a copy of the SQL . "SELECT FILE1.DOCUMENT_ID, FILE1.KEY1_DATA, FILE1.KEY2_DATA, FILE1.KEY3_DATA, FILE1.DATE, FILE2.OPTVOL From S12B4441.DVDTA.FILE1 FILE1 inner join S12B4441.DVDTA.FILE2 FILE2 on FILE1.DOCUMENT_ID = FILE2.DOCUMENT_ID inner join (SELECT RRN(FILE2) AS RECNUM, A.DOCUMENT_ID, A.OPTVOL FROM S12B4441.DVDTA.FILE2) SUB on RRN(EKD0310) +1 = SUB.RECNUM Where FILE1.OPTVOL <> ' ' AND FILE1.ITEM = 'D' AND FILE1.CABINET in('INSDOC', 'CHGDOC') ORDER BY FILE1OPTVOL DESC"
View Replies !
View Related
Selecting Records From One Column In A Table And Inserting..
Godwin writes "Hello, Heres my question.. I have 2 tables.2 paticular columns exist in both the tables. I want to be able to select those 2 columns on the 1st table and insert them on to the same 2 columns on the 2nd table. Now,this 2nd table has another 3 columns that exist in another table.I would like to take those 3 column values from that 3rd table and insert it into the 2nd table by modifying those existing records in the 2nd table.In the 3rd table,there will be around 5 records...I want to copy the existing records 5 times in the 2nd table and insert the 3rd tables rows inside the 2nd table in that respective column for 5 rows. I hope you understand what I mean...Im sorry for really confusing.. Please help me Thanks Godwin"
View Replies !
View Related
Choosing Between Two Column Values To Return As Single Column Value
I'm working on a social network where I store my friend GUIDs in a table with the following structure:user1_guid user2_guidI am trying to write a query to return a single list of all a users' friends in a single column. Depending on who initiates the friendship, a users' guid value can be in either of the two columns. Here is the crazy sql I have come up with to give what I want, but I'm sure there's a better way... Any ideas?SELECT DISTINCT UserIdFROM espace_ProfilePropertyWHERE (UserId IN (SELECT CAST(REPLACE(CAST(user1_guid AS VarChar(36)) + CAST(user2_guid AS VarChar(36)), @userGuid, '') AS uniqueidentifier) AS UserId FROM espace_UserConnection WHERE (user1_guid = @userGuid) OR (user2_guid = @userGuid))) AND (UserId IN (SELECT UserId FROM espace_ProfileProperty))
View Replies !
View Related
Counting Multiple Values From The Same Column And Grouping By A Another Column
This is a report I'm trying to build in SQL Reporting Services. I can do it in a hacky way adding two data sets and showing two tables, but I'm sure there is a better way. TheTable Order# Customer Status STATUS has valid values of PROCESSED and INPROGRESS The query I'm trying to build is Count of Processed and INProgress orders for a given Customer. I can get them one at a time with something like this in two different datasets and showing two tables, but how do I achieve the same in one query? Select Customer, Count (*) As Status1 FROM TheTable Where (Status = N'Shipped') Group By Customer
View Replies !
View Related
Table Column Names = Dataset Column Values?!
I need to create the following table in reporting services PRODUCT April March Feb 2008 2007 2008 2007 2008 2007 chair 8 9 7 4 4 4 table 3 4 5 6 4 6 My problem is the month names are a column in the dataset, but I dont know how to get it to fill as column headers??? Thanks in advance!!!
View Replies !
View Related
Selecting Column Criteria Based On Report Parameter
I have a report with a date type parameter. Depending on the value return by this date type parameter the dataset will return either the credit, deposit or process date. How do I go about coding it so that it will dynamically select the right column in my query for my dataset? Sincerely appreciate all the help I can get. Thanks in advance.
View Replies !
View Related
Add Values To A Column With Derived Column Expression?
Hi, how are you? I'm having a problem and I don't know if it can be solved with a derived column expression. This is the problem: We are looking data in a a sql database. We are writting the SQL result in a flat file. We need to transform data in one of the columns. For example: we can have 3 digits as value in a column but that column must be 10 digit length. So we have to complete all the missing digits with a zero. So, that column will have the original 3 digits and 7 zeros. How we can do that tranformation? We must do it from de the flat file or it can be a previous step? Thanks for any help you can give me. Regards, Beli
View Replies !
View Related
How To Create A New Column And Insert Values Into The New Column
Can anyone assist me with a script that adds a new column to a table then inserts new values into the new column based on the Table below. i have included an explanation of what the script should do. Column from Parts Table Column from MiniParts New Column in (Table 1 ) (Table 2 ) MiniParts (Table2) PartsNum MiniPartsCL NewMiniPartsCL 1 K DK 1 K K 1 Q Q 0 L L 0 L LC 0 D G 0 S S I have 2 tables in a database. Table 1 is Parts and Table 2 is MiniParts. I need a script that adds a new column in the MiniParts table. and then populate the new column (NewMinipartsCL) based on Values that exist in the PartsNum column in the Parts Table, and MiniPartsCL column in the MiniParts columns. The new column is NewMiniPartsCL. The table above shows the values that the new column (NewMiniPartsCL) should contain. For Example Anytime you have "1" in the PartsNum column of the Parts Table and the MiniPartsCL column of the MiniParts Table has a "K" , the NewMiniPartsCL column in the MiniParts Table should be populated with "DK" ( as shown in the table above). Anytime you have "1" in the PartsNum column of the Parts Table and the MiniPartsCL column of the MiniParts Table has a "K" , the NewMiniPartsCL column in the MiniParts Table should be populated with "K" ( as shown in the table above). etc..
View Replies !
View Related
Column Defaults As Parameters And/or Column Values
Good afternoon, I am trying to figure out a way to use a columns default value when using a stored procedure to insert a new row into a table. I know you are thinking "that is what the default value is for", but bare with me on this. Take the following table and subsequent stored procedure. In the table below, I have four columns, one of which is NOT NULL and has a default value set for that column. CREATE TABLE [dbo].[TestTable]( [FirstName] [nvarchar](50) NULL, [LastName] [nvarchar](50) NULL, [SSN] [nvarchar](15) NULL, [IsGeek] [bit] NOT NULL CONSTRAINT [DF_TestTable_IsGeek] DEFAULT ((1)) ) ON [PRIMARY] I then created the following stored procedure: CREATE PROCEDURE TestTable_Insert @FirstName nvarchar(50), @LastName nvarchar(50), @SSN nvarchar(15), @geek bit = NULL AS BEGIN INSERT INTO TestTable (FirstName, LastName, SSN, IsGeek) VALUEs (@FirstName, @LastName, @SSN, @geek) END GO and executed it as follows (without passing the @geek parameter value) EXEC TestTable_Insert 'scott', 'klein', '555-55-5555' The error I got back (and somewhat expected) is the following: Cannot insert the value NULL into column 'IsGeek', table 'ScottTest.dbo.TestTable'; column does not allow nulls. INSERT fails. What I would like to happen is for the table to use the columns default value and not the NULL value if I don't pass a parameter for @geek. OR, it would be really cool to be able to do something like this: INSERT INTO TestTable (FirstName, LastName, SSN, IsGeek) VALUEs (@FirstName, @LastName, @SSN, ISNULL(@geek, DEFAULT)) Does this make sense?
View Replies !
View Related
Sum Of Column Values Of Each Row In Another Column Of Same Table
Hi, I have got a table where i want to display sum of count(Column1), count(Column2) in another column.How can this be done? for example SELECT SUM(Count(pxInsName)+Count(pxFlowName)) AS "pySummaryCount(1)" , Count(pxInsName) AS "pySummaryCount(2)" , Count(pxFlowName) AS "pySummaryCount(3)" , pxAssignedOrg AS "pxAssignedOrg" , pxAssignedOrgDiv AS "pxAssignedOrgDiv" , pxAssignedOrgUnit AS "pxAssignedOrgUnit" FROM pc_assign_worklist WHERE pxObjClass = ? GROUP BY pxAssignedOrg , pxAssignedOrgDiv , pxAssignedOrgUnit ORDER BY 'pySummaryCount(1)' DESC But sum function can not be used on aggregate function. Is there any other way.
View Replies !
View Related
Combining Column Values Into One Column
Hi Folks, Im new to SQL, and I am trying to do the following: I have a table Documents with DocID, Path and FileName. A second table Keywords has KwdID, KeywordString A third table DocumentKeywords links the two with DocID,KwdID. Multiple keywords are linked to one document. I want to create a SELECT query that makes a result table that contains Path, FileName and Keywords columns where the Keywords column contains entries like "Keyword1,Keyword2,Keyword3" ie. a comma delimited list of keyword strings which have been built from the keywords that associate with a specific document. I found a nice sample here http://www.sqlteam.com/article/using-coalesce-to-build-comma-delimited-string which shows how to return just the comma delimited string itself: DECLARE @List varchar(100) SELECT @List = COALESCE(@List + ', ', '') + Keywords.KeywordString FROM DocumentKeywords WHERE KwdID = 1 SELECT @List I cannot seem to integrate this into the query so that it calculates the string for each row on the fly. My suspicion is that the capability is there. Can somebody point me in the right direction? Thanks
View Replies !
View Related
Help, Selecting Rows Based On Values In Other Rows...
I'm stuck. I have a table that I want to pull some info from that I don''t know how to. There are two colomuns, one is the call_id column which is not unique and the other is the call_status column which again is not unique. The call_status column can have several values, they are ('1 NEW','3 3RD RESPONDED','7 3RD RESOLVED','6 PENDING','3 SEC RESPONDED','7 SEC RESOLVED'). i.e example, this is the existing data. Call_id Call_Status 555555 3 3RD RESPONDED 235252 7 SEC RESOLVED 555555 7 3RD RESOLVED 325252 6 PENDING 555555 6 PENDING 325235 3 SEC RESPONDED 555555 1 NEW This is the data I want... Call_id Call_Status 555555 3 3RD RESPONDED 555555 6 PENDING 555555 7 3RD RESOLVED The call_id could be any number, I only want the 6 PENDING rows where there are other rows for that call_id which have either 3 3RD RESPONDED or 7 3RD RESOLVED. If someone knows how it would be a great help. Cheers, Chris
View Replies !
View Related
Selecting The Most Recently Edited Item AND Selecting A Certain Type If Another Doesn't Exist
I've got a big problem that I'm trying to figure out: I have an address table out-of-which I am trying to select mailing addresses for companies UNLESS a mailing address doesn't exist; then I want to select the physical addresses for that company. If I get multiple mailing or physical addresses returned I only want the most recently edited out of those. I don't need this for an individual ID select, I need it applied to every record from the table. My address table has some columns that look like: [AddressID] [int] [LocationID] [int] [Type] [nvarchar](10) [Address] [varchar](50) [City] [varchar](50) [State] [char](2) [Zip] [varchar](5) [AddDate] [datetime] [EditDate] [datetime] AddressID is a primary-key non-null column to the address table and the LocationID is a foreign key value from a seperate Companies table. So there will be multiple addresses to one LocationID, but each address will have it's own AddressID. How can I do this efficiently with perfomance in mind??? Thank you in advance for any and all replies...
View Replies !
View Related
How To Set Different Values Only To One Column
Is it possible to set different values to one column only with one sql command? With sql = "UPDATE Table set col = val1 where Pos = y1" ExecuteSQL(sql) sql = "UPDATE Table set col = val2 where Pos = y2" ExecuteSQL(sql) sql = "UPDATE Table set col = val3 where Pos = y3" ExecuteSQL(sql) ... I can set different values to one column, but that is very slow! -- and I have to set up to 500 different values to one column at different positions. For any reply thanks in advance. dlbergh
View Replies !
View Related
Column Containing 2 Values
Hi, I have a status column in Excel file which is getting data from checkboxes. When I exported my file to Excel this status column is containing 2 or more values. The possible values for status are: 1 active 2 Pending 3 Inactive So for each case it might be possible to get values like case 1: status: Active Pending Case 2 : Status: Inactive pending So in my Excel file is containing these values in one status column. I am thinking of storing statuses in a separate table like this: Case Active Pending inactive 1 1 1 0 2 0 1 1 In the SSIS transformation how to achive this? how to split the status columns values and where to store? Thanks
View Replies !
View Related
We Have A Column That Contains Values Only Between 0 And 1
We have a column that contains values only between 0 and 1; most of them are 0 or nearly 0. We perform a basic clustering on that single column with the data mining add-in for excel. The results show three clusters: two of them centered in values between 0 and 1 (0 and 0,47), the other one looks strange and has a very high negative value which is not present in our data. I haven€™t tried running the same clustering directly on Visual Studio. This hapend with other algortim. Do you know the problem We have screen dump if it needs Best regards Capgemini - Oslo
View Replies !
View Related
Dependent Columns
I have three columns (CWOC, C, and PWC). both CWOC and PWC are dependent on the value in C, yet C is dependent on the value in PWC. Basically: C = PWC * BR PWC = MR - CWOC CWOC = MC - C In setting up these columns in the database how do I set up columns like these that are so dependent on each other? This was set up previously in Excel using iteration, but now I'm recreating the application in VB.net and SQL Server. Thanks for your suggestions.
View Replies !
View Related
|