Trying To Write A Select Statement.
I want to write a select statement that will show only distinct Student IDs where every record in the table with that student id has a grade above 80?
Lets say for example the table looks like this:
Student_ID
Grade
11276
93
56879
81
11276
76
44327
92
11276
84
56879
97
56879
82 The select statement should only show students, 56879 & 44327 because student 11276 made a 76 in one class.Anyone know how to word this select statement?Thanks for any help!
View Complete Forum Thread with Replies
Related Forum Messages:
How To Write Select Statement Inside CASE Statement ?
Hello friends, I want to use select statement in a CASE inside procedure. can I do it? of yes then how can i do it ? following part of the procedure clears my requirement. SELECT E.EmployeeID, CASE E.EmployeeType WHEN 1 THEN select * from Tbl1 WHEN 2 THEN select * from Tbl2 WHEN 3 THEN select * from Tbl3 END FROM EMPLOYEE E can any one help me in this? please give me a sample query. Thanks and Regards, Kiran Suthar
View Replies !
How To Write The Select Statement?
I create a table that is named T1(C1,C2) and insert some data,as following: C1 C2 1 1 4 NULL NULL 5 7 NULL NULL 9 12 12 14 NULL NULL 16 I want to write a select statement to obtain the following result: C1 C2 1 1 4 5 7 9 12 12 14 16 how to write the select statement?  
View Replies !
Is It Possible To Write If/Then Else Within SQL Select Statement For Vb.net?
I'm running a select statement from within my VB.net code. However, if the software package name that I chose from a drop down list in my form is not available in the search (in the TableColumn called Software.Package_Name), I would like to be able to write the message "Record Not Found" to the Package_Name "ListBox" column. Here's the select statement: "SELECT n.Workstation_Name , s.install_status , s.install_date , s.name , s.version , s.build , s.Package_Name , n.city , n.state FROM software s , network n where ( s.mac=n.mac AND n.Workstation_Name='B001617CA709E' ) AND ( s.name='Adobe Reader' AND s.Install_status='1') ORDER BY n.Workstation_Name ASC" My ListBox control is named lstQueryResults and uses a Structure that is one to one with each row of the lstQueryResults control. i.e. Public Class LIST_CTRL_DATA Public WksName As String Public InstallStatus As String Public InstallDate As String Public PackageName As String Public AppName As String Public Version As String Public Build As String Public City As String Public State As String Public Percent As UInteger Finally, here's the While..End routine that plugs the data into the ListBox called lstQueryResults. While sqlReader.Read() currec += 1 Dim msg As THREAD_MESSAGE msg.msgid = 101 Dim message As New LIST_CTRL_DATA message.WksName = sqlReader("Workstation_Name").ToString message.InstallStatus = sqlReader("Install_Status").ToString message.InstallDate = sqlReader("Install_Date").ToString message.AppName = sqlReader("Name").ToString message.Version = sqlReader("Version").ToString message.Build = sqlReader("Build").ToString message.PackageName = sqlReader("Package_Name").ToString message.City = sqlReader("City").ToString message.State = sqlReader("State").ToString message.Percent = (currec * 100) / maxrecs msg.msgdata = message m_ParentWindow.Invoke(m_NotifyMainWindow, msg) End While Any ideas on whether or not you can write an If..Then Else statement within the SQL Select Statement and if so how? I'm still somewhat new to SQL. Any assistance would be great. Regards, NBK
View Replies !
How To Put Condition In Select Statement To Write A Cursor
col1 col2 col3 col4 36930.60 145 N . 00 17618.43 190 N . 00 6259.20 115 N .00 8175.45 19 N .00 18022.54 212 N .00 111.07 212 B .00 13393.05 67 N .00 In above 4 col if col3 value is B then cursor has to fectch appropriate value from col4. if col3 value is N then cursor has to fectch appropriate value from col1. here col2 values are unique. Can any one reply for this..............
View Replies !
Select Statement Within Select Statement Makes My Query Slow....
Hello... im having a problem with my query optimization.... I have a query that looks like this: SELECT * FROM table1 WHERE location_id IN (SELECT location_id from location_table WHERE account_id = 998) it produces my desired data but it takes 3 minutes to run the query... is there any way to make this faster?... thank you so much...
View Replies !
How To Write SQL Statement
I wanted to select few columns from the result of calling this store procedure and sort by a column. {CALL FIQR.Portfolio.Loans_In_Portfolio('2007-09-07', 'FISYND', '', '%')} How should I write it?(without changing the store procedure)
View Replies !
How Do I Write This SQL Statement?
I have a table named "products", it has a column called "category", I have data such as "CategoryA", "CategoryB" and "CategoryC" etc.... now I want to do a select statement and choose "CategoryA" and "CategoryB" but I want to rename them as "A" and "B". how do I write such a statement... thanks!
View Replies !
Help.. How To Write This Sql Statement?
Hi all, DECLARE @STA as char(50) SET @STA = 'TT' SELECT * FROM ABC_TBL where ABC_Filed in (@STA) if i have multivalue in parameter @STA, like 'TT', 'DD', 'AA' so how can i write my statement? i only need to pass one parameter with multilist, so do anybody know how to write the MS sql statement? Example like DECLARE @STA as char(50) SET @STA = 'TT', 'DD' SELECT * FROM ABC_TBL where ABC_Filed in (@STA) Thank You. Regards, S3ng
View Replies !
Is It Possible Write In 1 Query Statement?
Hi guys I'll appreciate any help with the following problem: Table 1: TBSALESHEADER PK: SALESNO Table 2: TBSALESENTRY FK: SALESNO This query is return 2 rows. SELECT PAYMTDID AS TYPE, CONVERT(CHAR(8),SALESDATE,112) AS DATE, SUM(SALESAMT) AS AMOUNT FROM TBSALESHEADER A, TBSALESENTRY B WHERE A.SALESNO = B.SALESNO AND CONVERT(CHAR(8),SALESDATE,112) = '20070701' GROUP BY PAYMTDID,CONVERT(CHAR(8),SALESDATE,112) TYPE DATE AMOUNT ---------------------------------------------------------- 0 20070701 3041.29 1 20070701 1442.20 Issue: Instead of retrieving 2 rows showing 2 type of records, I want to display the 2 type in 2 columns (need to return in 1 row). Can I get this desired result as following in 1 query statement: DATE AMOUNT (TYPE 1) AMOUNT (TYPE 2) --------------------------------------------------------------------------------- 20070701 3041.29 1442.20 Please help. Thanks.
View Replies !
How To Write A Delete Statement In Linked Server
Hi all, We are retriving tables from DB2 and loading into a SQL server. while retriving temporary tables are getting created in the linked server. we need to delete the data in those temporary tables in Linked server. I don't know how to write delete statement for the tables in linked server. any pointers would be appreciated. Thanks in advance. Shriram
View Replies !
I Want Write Select Without Field Name
hello my friends i want write Select without write filed name example mytable(id,name1,family) orginal selected is select id,name1 from mytable but i want write: select field[0],field[1] from my table that field[0] point to id and field[1] point to name1 thanx M.O.H.I.N
View Replies !
Multiple Tables Used In Select Statement Makes My Update Statement Not Work?
I am currently having this problem with gridview and detailview. When I drag either onto the page and set my select statement to pick from one table and then update that data through the gridview (lets say), the update works perfectly. My problem is that the table I am pulling data from is mainly foreign keys. So in order to hide the number values of the foreign keys, I select the string value columns from the tables that contain the primary keys. I then use INNER JOIN in my SELECT so that I only get the data that pertains to the user I am looking to list and edit. I run the "test query" and everything I need shows up as I want it. I then go back to the gridview and change the fields which are foreign keys to templates. When I edit the templates I bind the field that contains the string value of the given foreign key to the template. This works great, because now the user will see string representation instead of the ID numbers that coinside with the string value. So I run my webpage and everything show up as I want it to, all the data is correct and I get no errors. I then click edit (as I have checked the "enable editing" box) and the gridview changes to edit mode. I make my changes and then select "update." When the page refreshes, and the gridview returns, the data is not updated and the original data is shown. I am sorry for so much typing, but I want to be as clear as possible with what I am doing. The only thing I can see being the issue is that when I setup my SELECT and FROM to contain fields from multiple tables, the UPDATE then does not work. When I remove all of my JOIN's and go back to foreign keys and one table the update works again. Below is what I have for my SQL statements:------------------------------------------------------------------------------------------------------------------------------------- SELECT:SELECT People.FirstName, People.LastName, People.FullName, People.PropertyID, People.InviteTypeID, People.RSVP, People.Wheelchair, Property.[House/Day Hab], InviteType.InviteTypeName FROM (InviteType INNER JOIN (Property INNER JOIN People ON Property.PropertyID = People.PropertyID) ON InviteType.InviteTypeID = People.InviteTypeID) WHERE (People.PersonID = ?)UPDATE:UPDATE [People] SET [FirstName] = ?, [LastName] = ?, [FullName] = ?, [PropertyID] = ?, [InviteTypeID] = ?, [RSVP] = ?, [Wheelchair] = ? WHERE [PersonID] = ? ---------------------------------------------------------------------------------------------------------------------------------------The only fields I want to update are in [People]. My WHERE is based on a control that I use to select a person from a drop down list. If I run the test query for the update while setting up my data source the query will update the record in the database. It is when I try to make the update from the gridview that the data is not changed. If anything is not clear please let me know and I will clarify as much as I can. This is my first project using ASP and working with databases so I am completely learning as I go. I took some database courses in college but I have never interacted with them with a web based front end. Any help will be greatly appreciated.Thank you in advance for any time, help, and/or advice you can give.Brian
View Replies !
Using Conditional Statement In Stored Prcodure To Build Select Statement
hiI need to write a stored procedure that takes input parameters,andaccording to these parameters the retrieved fields in a selectstatement are chosen.what i need to know is how to make the fields of the select statementconditional,taking in consideration that it is more than one fieldaddedfor exampleSQLStmt="select"if param1 thenSQLStmt=SQLStmt+ field1end ifif param2 thenSQLStmt=SQLStmt+ field2end if
View Replies !
TSQL - Use ORDER BY Statement Without Insertin The Field Name Into The SELECT Statement
Hi guys, I have the query below (running okay): Code Block SELECT DISTINCT Field01 AS 'Field01', Field02 AS 'Field02' FROM myTables WHERE Conditions are true ORDER BY Field01 The results are just as I need: Field01 Field02 ------------- ---------------------- 192473 8461760 192474 22810 Because other reasons. I need to modify that query to: Code Block SELECT DISTINCT Field01 AS 'Field01', Field02 AS 'Field02' INTO AuxiliaryTable FROM myTables WHERE Conditions are true ORDER BY Field01 SELECT DISTINCT [Field02] FROM AuxTable The the results are: Field02 ---------------------- 22810 8461760 And what I need is (without showing any other field): Field02 ---------------------- 8461760 22810 Is there any good suggestion? Thanks in advance for any help, Aldo.
View Replies !
How To Write An Sql Crosstable Select Statment
Hi,would like to know how to write a crosstable select statment in sqlserver2000 where having:- ItemNumber, ItemDescription, ItemColor, ItemSize as rows- Stores as columns- Qty * Netttc as valuefrom Table salesthx*** Sent via Developersdex http://www.developersdex.com ***
View Replies !
Can I Write Multiple 'Select' Queries In Access? Please Help!
I'm trying to code a query in Access that finds rows w/ duplicate "ContactKeys" then finds duplicate "AddressLine1s" out of the list of duplicate "ContactKeys." (I tried subqueries but it was really slow) I am trying to create a new table with only duplicate ContactKey rows, and then I wanted to use that table to pick out the duplicate AddressLine1 rows. Code: SELECT * INTO dupContactKeys FROM Contacts WHERE ContactKey IN ( SELECT ContactKey FROM Contacts GROUP BY ContactKey HAVING COUNT(*) > 1) SELECT * FROM dupContactKeys WHERE ContactKey IN ( SELECT AddressLine1, Zip FROM Contacts GROUP BY AddressLine1, Zip HAVING COUNT(*) > 1) ORDER BY ContactKey, TypeKey; drop table dupContactKeys This of course doesn't work. Please help, as I am going slightly mad!
View Replies !
Select Criteria Based On Date - Cleaner Way To Write?
Code: SELECT (JUL_CURR_CREDITS + JUL_CURR_DEBITS + AUG_CURR_CREDITS + AUG_CURR_DEBITS + SEP_CURR_CREDITS + SEP_CURR_DEBITS + OCT_CURR_CREDITS + OCT_CURR_DEBITS + NOV_CURR_CREDITS + NOV_CURR_DEBITS + DEC_CURR_CREDITS + DEC_CURR_DEBITS + JAN_CURR_CREDITS + JAN_CURR_DEBITS + FEB_CURR_CREDITS + FEB_CURR_DEBITS + MAR_CURR_CREDITS + MAR_CURR_DEBITS + APR_CURR_CREDITS + APR_CURR_DEBITS + MAY_CURR_CREDITS + MAY_CURR_DEBITS + JUN_CURR_CREDITS + JUN_CURR_DEBITS) as CURR_AMT I need to sum these amounts running from July to the month prior to whatever the current month is. So if it was August, it would only be Code: SELECT (JUL_CURR_CREDITS + JUL_CURR_DEBITS) as CURR_AMT Is there a cleaner (shorter) way to iterate through the twelve months than either writing the query 12 times in an IF statement, or 12 CASE statements? This is only part of a query that joins several tables (not shown). Any suggestions on the best way to write this would be valued.
View Replies !
Help With Delete Statement/converting This Select Statement.
I have 3 tables, with this relation: tblChats.WebsiteID = tblWebsite.ID tblWebsite.AccountID = tblAccount.ID I need to delete rows within tblChats where tblChats.StartTime - GETDATE() < 180 and where they are apart of @AccountID. I have this select statement that works fine, but I am having trouble converting it to a delete statement: SELECT * FROM tblChats c LEFT JOIN tblWebsites sites ON sites.ID = c.WebsiteID LEFT JOIN tblAccounts accounts on accounts.ID = sites.AccountID WHERE accounts.ID = 16 AND GETDATE() - c.StartTime > 180
View Replies !
Select Statement Problem - Group By Maybe Nested Select?
Hey guys i have a stock table and a stock type table and what i would like to do is say for every different piece of stock find out how many are available The two tables are like thisstockIDconsumableIDstockAvailableconsumableIDconsumableName So i want to,Select every consumableName in my table and then group all the stock by the consumable ID with some form of total where stockavailable = 1I should then end up with a table like thisEpson T001 - Available 6Epson T002 - Available 0Epson T003 - Available 4If anyone can help me i would be very appreciative. If you want excact table names etc then i can put that here but for now i thought i would ask how you would do it and then give it a go myself.ThanksMatt
View Replies !
SQL Select Statement To Select The Last Ten Records Posted
SELECT Top 10 Name, Contact AS DCC, DateAdded AS DateTimeFROM NameTaORDER BY DateAdded DESC I'm trying to right a sql statement for a gridview, I want to see the last ten records added to the to the database. As you know each day someone could add one or two records, how can I write it show the last 10 records entered.
View Replies !
Using Select Statement Result In If Statement Please Help
Hello How can i say this I would like my if statement to say: if what the client types in Form1.Cust is = to the Select Statement which should be running off form1.Cust then show the Cust otherwise INVALID CUSTOMER NUMBER .here is my if statement. <% If Request.Form("Form1.Cust") = Request.QueryString("RsCustNo") Then%> <%=Request.Params("Cust") %> <% Else %> <p>INVALID CUSTOMER NUMBER</p> <% End If%> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:RsCustNo %>" ProviderName="<%$ ConnectionStrings:RsCustNo.ProviderName %>" SelectCommand="SELECT [CU_CUST_NUM] FROM [CUSTOMER] WHERE ([CU_CUST_NUM] = ?)"> <SelectParameters> <asp:FormParameter FormField="Cust" Name="CU_CUST_NUM" Type="String" /> </SelectParameters> </asp:SqlDataSource>any help would be appreciated
View Replies !
If STATEMENT Within Select Statement Syntax
Hi, I am a newbie to this site and hope someone can help.... I have a select statement which I would like to create an extra column and put an if statement in it.... Current syntax is: if(TL_flag= '1', "yes") as [Trial Leave] it is coming up with an error.... I can use Select case but I should not need to as this should work? Any ideas?
View Replies !
How To Write SQL To Form &&"New Table&&" From Job Revence And Job Cost Using SQL Statement ? Thx
Edited by SomeNewKid. Please post code between <code> and </code> tags. // Pls copy the following HTML after that you generate the HTML page. Then you will know what I mean. I need to form "New Table" from Job Revence and Job Cost using SQL statement? thx -----------The following code----------------- <META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=big5"> <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv=Content-Type content="text/html; charset=Big5"> <meta name=ProgId content=Excel.Sheet> <meta name=Generator content="Microsoft Excel 9"> <link rel=File-List href="cid:filelist.xml@01C4DA4E.7D08F5E0"> <!--[if !mso]> <style> v:* {behavior:url(#default#VML);} o:* {behavior:url(#default#VML);} x:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style> <![endif]--> <style> <!--table {mso-displayed-decimal-separator:"."; mso-displayed-thousand-separator:",";} .xl15 {padding-top:1px; padding-right:1px; padding-left:1px; mso-ignore:padding; color:windowtext; font-size:9.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:????; mso-generic-font-family:auto; mso-font-charset:136; mso-number-format:General; text-align:general; vertical-align:bottom; mso-background-source:auto; mso-pattern:auto; white-space:nowrap;} .xl22 {padding-top:1px; padding-right:1px; padding-left:1px; mso-ignore:padding; color:windowtext; font-size:9.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:????; mso-generic-font-family:auto; mso-font-charset:136; mso-number-format:General; text-align:general; vertical-align:bottom; border:.5pt solid windowtext; mso-background-source:auto; mso-pattern:auto; white-space:nowrap;} .xl23 {padding-top:1px; padding-right:1px; padding-left:1px; mso-ignore:padding; color:windowtext; font-size:9.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:????; mso-generic-font-family:auto; mso-font-charset:136; mso-number-format:General; text-align:general; vertical-align:bottom; border:.5pt solid windowtext; background:#339966; mso-pattern:auto none; white-space:nowrap;} .xl24 {padding-top:1px; padding-right:1px; padding-left:1px; mso-ignore:padding; color:windowtext; font-size:12.0pt; font-weight:700; font-style:normal; text-decoration:none; font-family:????, serif; mso-font-charset:136; mso-number-format:General; text-align:general; vertical-align:bottom; mso-background-source:auto; mso-pattern:auto; white-space:nowrap;} --> </style> <!--[if gte mso 9]><xml> <x:ExcelWorkbook> <x:ExcelWorksheets> <x:ExcelWorksheet> <x:Name>Sheet1</x:Name> <x:WorksheetOptions> <x:DefaultRowHeight>225</x:DefaultRowHeight> <x:Print> <x:ValidPrinterInfo/> <x:PaperSizeIndex>9</x:PaperSizeIndex> <x:HorizontalResolution>-3</x:HorizontalResolution> <x:VerticalResolution>0</x:VerticalResolution> </x:Print> <x:Selected/> <x:Panes> <x:Pane> <x:Number>3</x:Number> <x:ActiveCol>10</x:ActiveCol> </x:Pane> </x:Panes> <x:ProtectContents>False</x:ProtectContents> <x:ProtectObjects>False</x:ProtectObjects> <x:ProtectScenarios>False</x:ProtectScenarios> </x:WorksheetOptions> </x:ExcelWorksheet> </x:ExcelWorksheets> <x:WindowHeight>10470</x:WindowHeight> <x:WindowWidth>16755</x:WindowWidth> <x:WindowTopX>240</x:WindowTopX> <x:WindowTopY>30</x:WindowTopY> <x:HasEnvelope/> <x:ProtectStructure>False</x:ProtectStructure> <x:ProtectWindows>False</x:ProtectWindows> </x:ExcelWorkbook> </xml><![endif]--> </head> <body> <table x:str border=0 cellpadding=0 cellspacing=0 width=636 style='border-collapse: collapse;table-layout:fixed;width:477pt'> <col width=56 span=7 style='width:42pt'> <col width=104 style='mso-width-source:userset;mso-width-alt:4437;width:78pt'> <col width=140 style='mso-width-source:userset;mso-width-alt:5973;width:105pt'> <tr height=22 style='height:16.5pt'> <td height=22 class=xl24 colspan=2 width=112 style='height:16.5pt;mso-ignore: colspan;width:84pt'>JOB TABLE</td> <td class=xl15 width=56 style='width:42pt'></td> <td class=xl15 width=56 style='width:42pt'></td> <td class=xl15 width=56 style='width:42pt'></td> <td class=xl15 width=56 style='width:42pt'></td> <td class=xl15 width=56 style='width:42pt'></td> <td class=xl15 width=104 style='width:78pt'></td> <td class=xl15 width=140 style='width:105pt'></td> </tr> <tr height=15 style='height:11.25pt'> <td height=15 class=xl23 style='height:11.25pt'>JobNo</td> <td colspan=8 class=xl15 style='mso-ignore:colspan'></td> </tr> <tr height=15 style='height:11.25pt'> <td height=15 class=xl22 style='height:11.25pt;border-top:none'>SE0001</td> <td colspan=8 class=xl15 style='mso-ignore:colspan'></td> </tr> <tr height=22 style='height:16.5pt'> <td height=22 class=xl22 style='height:16.5pt;border-top:none'>SE0002</td> <td colspan=5 class=xl15 style='mso-ignore:colspan'></td> <td class=xl24 colspan=2 style='mso-ignore:colspan'>New Table</td> <td class=xl15></td> </tr> <tr height=15 style='height:11.25pt'> <td height=15 colspan=6 class=xl15 style='height:11.25pt;mso-ignore:colspan'></td> <td class=xl23>JobNo</td> <td class=xl23 style='border-left:none'>no of Revence</td> <td class=xl23 style='border-left:none'>no of Cost</td> </tr> <tr height=22 style='height:16.5pt'> <td height=22 class=xl24 colspan=2 style='height:16.5pt;mso-ignore:colspan'>JOB Revence</td> <td colspan=4 class=xl15 style='mso-ignore:colspan'></td> <td class=xl22 style='border-top:none'>SE0001</td> <td class=xl22 align=right style='border-top:none;border-left:none' x:num>2</td> <td class=xl22 align=right style='border-top:none;border-left:none' x:num>1</td> </tr> <tr height=15 style='height:11.25pt'> <td height=15 class=xl23 style='height:11.25pt'>JobNo</td> <td class=xl23 style='border-left:none'>ItemNo</td> <td colspan=4 class=xl15 style='mso-ignore:colspan'></td> <td class=xl22 style='border-top:none'>SE0002</td> <td class=xl22 align=right style='border-top:none;border-left:none' x:num>1</td> <td class=xl22 align=right style='border-top:none;border-left:none' x:num>0</td> </tr> <tr height=15 style='height:11.25pt'> <td height=15 class=xl22 style='height:11.25pt;border-top:none'>SE0001</td> <td class=xl22 align=right style='border-top:none;border-left:none' x:num>1</td> <td colspan=7 class=xl15 style='mso-ignore:colspan'></td> </tr> <tr height=15 style='height:11.25pt'> <td height=15 class=xl22 style='height:11.25pt;border-top:none'>SE0001</td> <td class=xl22 align=right style='border-top:none;border-left:none' x:num>2</td> <td colspan=7 class=xl15 style='mso-ignore:colspan'></td> </tr> <tr height=15 style='height:11.25pt'> <td height=15 class=xl22 style='height:11.25pt;border-top:none'>SE0002</td> <td class=xl22 align=right style='border-top:none;border-left:none' x:num>1</td> <td colspan=7 class=xl15 style='mso-ignore:colspan'></td> </tr> <tr height=15 style='height:11.25pt'> <td height=15 colspan=9 class=xl15 style='height:11.25pt;mso-ignore:colspan'></td> </tr> <tr height=22 style='height:16.5pt'> <td height=22 class=xl24 colspan=2 style='height:16.5pt;mso-ignore:colspan'>JOB Cost</td> <td colspan=7 class=xl15 style='mso-ignore:colspan'></td> </tr> <tr height=15 style='height:11.25pt'> <td height=15 class=xl23 style='height:11.25pt'>JobNo</td> <td class=xl23 style='border-left:none'>ItemNo</td> <td colspan=7 class=xl15 style='mso-ignore:colspan'></td> </tr> <tr height=15 style='height:11.25pt'> <td height=15 class=xl22 style='height:11.25pt;border-top:none'>SE0001</td> <td class=xl22 align=right style='border-top:none;border-left:none' x:num>1</td> <td colspan=7 class=xl15 style='mso-ignore:colspan'></td> </tr> <![if supportMisalignedColumns]> <tr height=0 style='display:none'> <td width=56 style='width:42pt'></td> <td width=56 style='width:42pt'></td> <td width=56 style='width:42pt'></td> <td width=56 style='width:42pt'></td> <td width=56 style='width:42pt'></td> <td width=56 style='width:42pt'></td> <td width=56 style='width:42pt'></td> <td width=104 style='width:78pt'></td> <td width=140 style='width:105pt'></td> </tr> <![endif]> </table> </body> </html>
View Replies !
Using IF...Else Statement SELECT Statement
Hi All, Can some one point me in the right direction in how to construct my SQL query within my cursor? I Have got a cursor which i am using to iterate through a table, What i am trying to do is in my statement(used to open the cursor) is compare 2 tables (the one which my cursor is iterating) to see if there is a matching row in the other table (using both tables ID's Like So: SELECT column_List FROM Table1 WHERE Table1_id = Table2_id so for each row my cursor checks if there is a corresponding match in table2... but i would like to write to an error log and do other statements if there is no match how do i add this condition to my statement either using an if...else statement proceeding to the next row? here is the statment i attempted to write: SELECT column_List FROM table1 WHERE Table1_id = Table2.id now i want to incoporate the statements below into the statement above as a condition when table1.id <> table2.id IF table1.id <> table2.id BEGIN SET @DebugMessage = 'data not live.' RAISERROR (@DebugMessage, 16, 1) WITH LOG END essentially what i am trying to sayin my statement is: go to the first row check if it has a match in table 2, if there is no match execute a number of statements such as error loging e.t.c go to the next row repeat the previous statements ...i also looked through some Case...When statements am just not sure how to put in the condition thanks in advance
View Replies !
SQL Select Statement
I have a database that is constantly being added to... what im trying to do is select the 10 most recent entries EXCEPT for the very most recent. Selecting the 10 most recent is something I can do.... 'select top 10 * from tablename order by id desc' - but how do I leave out the most recent? SQL Server 2005
View Replies !
SELECT Statement
Hi,I'm sorry for the lame question, but I''m a newbie at C#.With the code that follows my signature, I'm trying to retrieve a single value from a table.The query is ok, I've tested manually.But I get the error:"The name userPassword does not exist in the current context".I realize it's a matter of scope, but I need to have the variable value available there.Furthermore, I think that I'm getting no result from the database with my code, because if I put the Response.Write(userPassword) line inside the while cicle, nothing is displayed.Any help would be appreciated.Warm Regards,Mário Gamito--SqlConnection myConn = new SqlConnection("user id=sa" + "password=secret" + "server=192.168.1.4" + "database=workers");try{myConn.Open()}catch (Exception e){Console.WriteLine(e.ToString());}try{SqlDataReader myReader = null;SqlCommand myCommand = new SqlCommand("SELECT password FROM dbo.users WHERE email = 'gamito@foobar.lan'", myConn);myReader = myCommand.ExecuteReader();while(myReader.Read()) { string userPassword = myReader["password"].ToString()); }}catch (Exception e){ Console.WriteLine(e.ToString());}myConn.Close();Response.Write(userPassword);
View Replies !
Max Select Statement
Hi Guys, Having a little problem, can someone take a look at this... Thank You... Trying to get the Max(WebNameTitle) From Max(NumerID) Example code below throws error : I need the Max Value from the Column( WebNameTitle <---nvarchar) and the Max Value from the Column (NumberID <--int) New SqlCommand("Select Max(WebNameTitle) FROM ComBooks WHERE Max(NumberID) = MaxNumberID", conCommerce)
View Replies !
Select Statement In ASP.NET
hello all, I need to SELECT data in my ASP.NET web service from my MSSQLExpress database. I checked to INSERT data into it and it worked well , and here is the code of my insert: 1 <WebMethod()> _2 Public Function SaveNumName(ByVal UserNum As Integer, ByVal UserName As String)3 Dim DS As New SqlDataSource4 5 DS.ConnectionString = "Data Source=.SQLEXPRESS;Persist Security Info=True;Integrated Security=SSPI;Initial Catalog=tstSQL"6 ' DS.ConnectionString = ConfigurationManager.ConnectionStrings("tstSQLConnectionString1")7 DS.InsertCommandType = SqlDataSourceCommandType.Text8 DS.InsertCommand = "insert into tbl1 (number,name) values (@number,@name)"9 DS.InsertParameters.Add("number", UserNum)10 DS.InsertParameters.Add("name", UserName)11 12 DS.Insert()13 14 Return 115 End Function The previous code worked well for the insertion of data, but when I tryed the same technique with the selection of data, it didn't work, and here is my code for the select: 1 <WebMethod()> _2 Public Function GetName(ByVal Number As Integer)3 Dim Name As String4 'Dim ConnStr As String = "Data Source=.SQLEXPRESS;Persist Security Info=True;Integrated Security=SSPI;Initial Catalog=malalation_tstSQL"5 Dim GV As New GridView6 GV.Visible = False7 Dim DS As New SqlDataSource8 DS.ConnectionString = "Data Source=.SQLEXPRESS;Persist Security Info=True;Integrated Security=SSPI;Initial Catalog=tstSQL"9 10 DS.SelectCommandType = SqlDataSourceCommandType.Text11 DS.SelectCommand = "SELECT name from tbl1 where number = 1"12 ' DS.Select()13 GV.DataSource = DS14 Name = GV.Rows(0).Cells(1).Text15 Return Name16 End Function I think that the problem is with storing the result of the SELECT satatement, so what do you think??
View Replies !
Need Help With SELECT Statement
Hi, I have a table (SQL 2000) that holds inside login records of each system. All the systems logging 0-50 times each day. I need to create “Last Login� report that shows as following: SystemID LastLogin System001 2008-04-23 21:14:49 System002 2008-03-12 21:15:06 System003 2008-01-20 22:14:15 System004 2008-04-23 22:14:24 System005 2008-02-23 22:14:42 Need help with SELECT statement Thanks in advance. Alex
View Replies !
Select Statement
Hi Guys, I have some problem with sqlquery can any one help? Here is my statement strSQL=strSQL & "employee= "Select empname from tbl_emp where empname= strUname" when executing it says Expected end of statement Thanks
View Replies !
Select Statement Help
Hello I only need to get the row from InvoiceHeader where branchID = 116The problem is I'm also getting the rows from InvoiceDetail where branchID is stored how will I solve this? Here's the code. SelectBranch.BranchLocation,Receipt.InvoiceNo,Receipt.AmountPaidFrom ReceiptINNER JOIN InvoiceHeader ON Receipt.InvoiceNo = InvoiceHeader.InvoiceNoINNER JOIN InvoiceDetail ON InvoiceHeader.InvoiceNo = InvoiceDetail.InvoiceNoINNER JOIN Branch ON InvoiceDetail.BranchID = Branch.BranchIDWhereBranch.BranchID = 116
View Replies !
Select Statement
Hi all,Can u plz tell me what is wrong with this select statement "select sku from products where cat='" & catitems.SelectedValue.Replace("'", "''") & "' and subcat is nothing" plz help regards
View Replies !
Help Me With A SELECT Statement, Please
hello i have two tables: ProductComments (CommentID, ProductID, UserName, Comment, Date) and Users (UserName, City, Age) i need to SELECT * FROM ProductComments where ProductID = @ProductID, and select from Users Table info about the users who commented i need some help, because i'm not so good at SQL yet:( thank you
View Replies !
Select Statement
The following Select statement shows "distinct l.userid" for the available c.id. I would like to see all the "c.id" even if "distinct l.userid" are NULL. select c.id, count(distinct l.userid) from Companys c left join labvalues l on c.id = l.companyid where l.labdate>='01/01/2007' and l.labdate <'02/01/2007' and c.id in (1,2,3,4,5,6,7) Output: 1 12 2 13 7 25 Expected Output: 1 12 2 13 3 NULL 4 NULL 5 NULL 6 NULL 7 25 PLEASE HELP......
View Replies !
Need Help With This Select Statement
I have a table called fund and a another table called FundPerformance.. and they both are linked together using FundId.. But suppose if a fund doesnt have any performance information.. It doesnt have a entry in the FundPerformance table but has a entry in the Fund table... I have written select statement that would give me the results.. But suppose if that particular fund is not present in the fundperformance table that fund doesnt show up in the select query.. So how can i get it.. I tried Inner Join, Left Outer Join and Right Outer join but it doesnt show up at all.SELECT pf.FundId, dbo.udf_Quarter(Getdate()) PeriodId, f.FundName, CASE WHEN pf.PlanFundDisplayName IS NULL THEN f.ShortName ELSE pf.PlanFundDisplayName END FundNames, f.InvestmentPolicy, f.FundClassCd, c.ClassName, c.ClassDefinition, p.YearToDate, p.OneYear, p.ThreeYear, p.FiveYear, p.TenYear, p.SinceInception, f.ExpenseRatio, f.PortfolioManager, f.AssetAllocationCashPercent CashAllocPct, f.AssetAllocationEquityPercent EquityAllocPct, f.AssetAllocationConvertiblesPercent ConvertAllocPct, f.AssetAllocationFixedIncomePercent FixedIncAllocPct, f.AssetAllocationOtherPercent OtherAlloc, p.TotalNetAssets, p.AsOfDate FROM PlanFund pf Right Outer JOIN Fund f Right Outer JOIN FundClass c ON f.FundClassCd = c.FundClassCd Right Outer Join FundPerformance p on f.FundId = p.FundId ON f.FundId = pf.FundId --Left Outer JOIN FundPerformance p --ON pf.FundId = p.FundId WHERE pf.PlanId = @PlanId AND p.PeriodId = dbo.udf_Quarter(Getdate()) --PeriodId --@PeriodId ORDER BY pf.FundDisplayOrder any help will be appreciated Regards, Karen
View Replies !
Regarding Select Statement
How to select two different fields from two different tables depending on the ID in a query. For Example: A from table1 and c from table 2 must be selected depending on the ID of table1 and Id of table2. please help me.
View Replies !
Help Me With A SELECT Statement Please
hello i am trying to make a select statement between two tables and i don't know how to start doing that i have two tables: UserComments where i store each comment made by all users and the Pictures table, and in one of his rows "LastComment" i store the userName -varchar(255)- of the user who last commented that picture i need to make a select statement with one input parameter (userName of the logged in user) and two output parameters(int) (@totalComments - would come from the UserComments table, and @lastComments - would come from the Pictures table) @totalComments - i need to COUNT how many comments that user has made from the UserComments @lastComments - count at how many pictures that user is last commenter from the Pictures there is no relation between these two tables, i can make two stored procedures one for each COUNT but i think is stresfull for the database please help me, thanks
View Replies !
Use If Statement In Select Sql
Hi. i have the database with status field (true,false) in access i have the cod in vb.net strSqlQuery="select id,name,status FROM... how i can use the IF in this code,as strSqlQuery="select id,name, if (status=true then status="ok" else "No") FROM table.... thanks
View Replies !
Select Statement
Hi, I dont know whts wrong with this plz help??? strQry = "Select classlevel, classcharge, classCost, classcharge - classcost from cart_shipping_chargeLevel order by [classlevel] assending" plz help regards,.
View Replies !
Select Statement
Hi there, I have a table which has lab values.... id, userid, companyid, testid, testname, value, labdate I want to write a select statement which will give me, fixed 5 tests for some userids. Something like..... select testid=1 testid=2 testid=3 testid=4 testid=5 from labvalues where userid in (11,12,13,14,15,16,17,18,19,20) PLEASE HELP THANKS
View Replies !
|