Is There An Equivalent Syntax To TOP IN SQL?
May 16, 2006
Hi everyone, I am new to SQL, and would really appreciate help with this.
I have a database with the following fields:
IDNumber: sequential running from 1 to approx 50000
SURNAME: Surname
FNAME: Forename.
I want to return the last 100 IDNUmbers and return the surname and fname associated with the IDNumbers.
When I try TOP it gives me IDNumbers 1 to 100, is there an equilvant for the bottom 100 numbers.
Please help if you can.
Thanks
Scott
View 2 Replies
ADVERTISEMENT
Mar 12, 2007
Hello,
In this sql syntax
Quote: "SELECT table1.ID, table1.Catagory, table1.PostCount, table1.LastPostDate, table1.Description, table2.Username, table2.ID AS UserID FROM Catagories AS table1 INNER JOIN Users AS table2 ON table1.LastPostBy = table2.ID"
Is this the equivalent?
Quote: “SELECT table1.ID, table1.Catagory, table1.PostCount, table1.LastPostDate, table1.Description, table2Username, table2ID AS UserID FROM Categories AS table, Users AS table 2 WHERE table1.LastPostby = table2.ID”
View 7 Replies
View Related
May 20, 2008
Why does the following call to a stored procedure get me this error:
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'CONVERT'.
Code Snippet
EXECUTE OpenInvoiceItemSP_RAM CONVERT(DATETIME,'01-01-2008'), CONVERT(DATETIME,'04/30/2008') , 1,'81350'
The stored procedure accepts two datetime parameters, followed by an INT and a varchar(10) in that order.
I can't find anything wrong in the syntax for CONVERT or any nearby items.
Help me please. Thank you.
View 7 Replies
View Related
Dec 14, 2003
I keep receiving the following error whenever I try and call this function to update my database.
The code was working before, all I added was an extra field to update.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'WHERE'
Public Sub MasterList_Update(sender As Object, e As DataListCommandEventArgs)
Dim strProjectName, txtProjectDescription, intProjectID, strProjectState as String
Dim intEstDuration, dtmCreationDate, strCreatedBy, strProjectLead, dtmEstCompletionDate as String
strProjectName = CType(e.Item.FindControl("txtProjectName"), TextBox).Text
txtProjectDescription = CType(e.Item.FindControl("txtProjDesc"), TextBox).Text
strProjectState = CType(e.Item.FindControl("txtStatus"), TextBox).Text
intEstDuration = CType(e.Item.FindControl("txtDuration"), TextBox).Text
dtmCreationDate = CType(e.Item.FindControl("txtCreation"),TextBox).Text
strCreatedBy = CType(e.Item.FindControl("txtCreatedBy"),TextBox).Text
strProjectLead = CType(e.Item.FindControl("txtLead"),TextBox).Text
dtmEstCompletionDate = CType(e.Item.FindControl("txtComDate"),TextBox).Text
intProjectID = CType(e.Item.FindControl("lblProjectID"), Label).Text
Dim strSQL As String
strSQL = "Update tblProject " _
& "Set strProjectName = @strProjectName, " _
& "txtProjectDescription = @txtProjectDescription, " _
& "strProjectState = @strProjectState, " _
& "intEstDuration = @intEstDuration, " _
& "dtmCreationDate = @dtmCreationDate, " _
& "strCreatedBy = @strCreatedBy, " _
& "strProjectLead = @strProjectLead, " _
& "dtmEstCompletionDate = @dtmEstCompletionDate, " _
& "WHERE intProjectID = @intProjectID"
Dim myConnection As New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("connectionstring"))
Dim cmdSQL As New SqlCommand(strSQL, myConnection)
cmdSQL.Parameters.Add(new SqlParameter("@strProjectName", SqlDbType.NVarChar, 40))
cmdSQL.Parameters("@strProjectName").Value = strProjectName
cmdSQL.Parameters.Add(new SqlParameter("@txtProjectDescription", SqlDbType.NVarChar, 30))
cmdSQL.Parameters("@txtProjectDescription").Value = txtProjectDescription
cmdSQL.Parameters.Add(new SqlParameter("@strProjectState", SqlDbType.NVarChar, 30))
cmdSQL.Parameters("@strProjectState").Value = strProjectState
cmdSQL.Parameters.Add(new SqlParameter("@intEstDuration", SqlDbType.NVarChar, 60))
cmdSQL.Parameters("@intEstDuration").Value = intEstDuration
cmdSQL.Parameters.Add(new SqlParameter("@dtmCreationDate", SqlDbType.NVarChar, 15))
cmdSQL.Parameters("@dtmCreationDate").Value = dtmCreationDate
cmdSQL.Parameters.Add(new SqlParameter("@strCreatedBy", SqlDbType.NVarChar, 10))
cmdSQL.Parameters("@strCreatedBy").Value = strCreatedBy
cmdSQL.Parameters.Add(new SqlParameter("@strProjectLead", SqlDbType.NVarChar, 15))
cmdSQL.Parameters("@strProjectLead").Value = strProjectLead
cmdSQL.Parameters.Add(new SqlParameter("@dtmEstCompletionDate", SqlDbType.NVarChar, 24))
cmdSQL.Parameters("@dtmEstCompletionDate").Value = dtmEstCompletionDate
cmdSQL.Parameters.Add(new SqlParameter("@intProjectID", SqlDbType.NChar, 5))
cmdSQL.Parameters("@intProjectID").Value = intProjectID
myConnection.Open()
cmdSQL.ExecuteNonQuery
myConnection.Close()
MasterList.EditItemIndex = -1
BindMasterList()
End Sub
Thankyou in advance.
View 3 Replies
View Related
Mar 31, 2008
Forgive the noob question, but i'm still learning SQL everyday and was wondering which of the following is faster? I'm just gonna post parts of the SELECT statement that i've made changes to:
INNER JOIN Facilities f ON e.Facility = f.FacilityID AND f.Name = @FacilityName
OR
WHERE f.Name = @FacilityName
My question is whether or not the query runs faster if i put the condition within the JOIN line as opposed to putting in the WHERE line? Both ways seems to return the same results but the time difference between methods is staggering? Putting the condition within the JOIN line makes the query run about 3 times faster?
Again, forgive my lack of understanding, but could someone agree or disagree and give me the cliff-notes version of why or why not?
Thanks!
View 4 Replies
View Related
Sep 23, 2007
Ok I am tying to convert access syntax to Sql syntax to put it in a stored procedure or view..
Here is the part that I need to convert:
SELECT [2007_hours].proj_name, [2007_hours].task_name, [2007_hours].Employee,
IIf(Mid([task_name],1,3)='PTO','PTO_Holiday',
IIf(Mid([task_name],1,7)='Holiday','PTO_Holiday',
IIf(Mid([proj_name],1,9) In ('9900-2831','9900-2788'),'II Internal',
IIf(Mid([proj_name],1,9)='9900-2787','Sales',
IIf(Mid([proj_name],1,9)='9910-2799','Sales',
IIf(Mid([proj_name],1,9)='9920-2791','Sales',
)
)
)
)
) AS timeType, Sum([2007_hours].Hours) AS SumOfHours
from................
how can you convert it to sql syntax
I need to have a nested If statment which I can't do in sql (in sql I have to have select and from Together for example ( I can't do this in sql):
select ID, FName, LName
if(SUBSTRING(FirstName, 1, 4)= 'Mike')
Begin
Replace(FirstNam,'Mike','MikeTest')
if(SUBSTRING(LastName, 1, 4)= 'Kong')
Begin
Replace(LastNam,'Kong,'KongTest')
if(SUBSTRING(Address, 1, 4)= '1245')
Begin
.........
End
End
end
Case Statement might be the solution but i could not do it.
Your input will be appreciated
Thank you
View 5 Replies
View Related
Nov 23, 2005
I have looked around and found the equivalent for IIF (Access) to be aSELECT CASE in SQL. I have tried this with no success. I am also lookingfor the equivalent of MAX and have had no luck. The portion of thestring I am trying to SQL'ize is:SELECT Max(IIf([ADCN.ADCN] Is Null,0,[ADCN.ADCN])) AS ADCN FROM ADCNINNER JOIN Sheet ON ADCN.RecordID = Sheet.RecordID WHERE (Sheet.Drawing= '" & x & "') AND (Sheet.SheetNumber = 0);This portion is the most important:SELECT Max(IIf([ADCN.ADCN] Is Null,0,[ADCN.ADCN])) AS ADCN*** Sent via Developersdex http://www.developersdex.com ***
View 3 Replies
View Related
Aug 15, 2006
Recently, my company's deveolpment machine crashed. We had to format the harddrive which meant we lost some of our databases.
We managed to restore the databases, but we do not know in what state, i.e. which stored procedures were written between the restore point and the point the machine crashed.
Tow questions related to this:
1. I was wondering if there is any product that is similar to soursesafe but appied to databases, so that this problem will not happen again. Does Enterprise manager do something like this?
2. I was also wondering if there was anyway to undo an sql command. e.g. my colleague recently ran a command to update a database, but forgot to write the where clause!! That data was recovered aswell, but it would be nice to have some sort of undo button.
Thanks in advance.
Jagdip
View 1 Replies
View Related
Dec 28, 2006
Is there anyway I can return only the last row of a query, like TOP does for the top most items?I would like to return something like this:SELECT BOTTOM 1 Column_CFROM Table1WHERE Column_A = somethingAny help would be greatly appreciated. Thank you!
View 3 Replies
View Related
Jan 7, 2008
Hi everyoneI have a table 'users' with column 'residence' New York, NY Houston, TXSan Antonio, TX In MySQL I can select the city by running the following command SELECT SUBSTRING_INDEX(residence, ',' , 1) FROM users. How would I accomplish the same thing using ms sql? Thanks in advance
View 2 Replies
View Related
Jul 10, 2004
Hi
Is there and equivalent of rs.getrows in asp.net? I want to fill an array quickly from a datareader?
ta
Lbob
View 2 Replies
View Related
Jun 20, 2001
What is the equivalent to autonumber in SQL 7? I ported over some data into SQL but when I bring it up in Access 97 as linked tables it shows that
what used to be autonumber in Access is listed only as number in SQL. So what is the equivalent to Autonumber in SQL?
View 1 Replies
View Related
May 6, 2008
!#perl
How do i structure my script to do the same thing in SQLExpress as in MySQL. My MySQL statement goes like:
ALTER TABLE groups ADD Last_Updated timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP AFTER Report_List
SQL does not recognize the ON UPDATE part, but i want the same function out of that collumn.
Any help here is greatly appreciated,
??
JOhn
View 11 Replies
View Related
Jun 16, 2004
Hi,
There is a concept called INDEXTYPE in Oracle, Is there any equivallent for the same in SQL Server ?
Oracle example :
CREATE INDEX index1 ON test_table(col1) INDEXTYPE IS CTXSYS.CONTEXT
What is the SQL Server equivalent query for the above ?
Thanks,
Sam
View 1 Replies
View Related
Jul 8, 2004
Hi,
What is the SQL Server equivalent for "set autocommit on" of Oracle ?
Thanks,
Sam
View 4 Replies
View Related
Jul 9, 2004
I have 2 SQL statements in Visual Basic(with sybase as backend)
1) "set option DBA.MAX_STATEMENT_COUNT = 1069999900"
2) "set option DBA.MAX_CURSOR_COUNT = 1069999900"
And when I migrated the DB from Sybase to SQL server and try to run the vb code it is giving me error in that SQL statement as MS SQL server might not be recognising the above two statements. Is there an equivalent of this in SQL server.
Thanks
View 1 Replies
View Related
Aug 16, 2004
Hi,
Rownum returns the serial number for the records in Oracle.
Id there an equivalent for the same in SQL Server ?
select rownum from test_table;
Please advise,
Thanks
Sam
View 1 Replies
View Related
Oct 27, 2004
Oracle query :
create table test(sno int, sno1 int) NOCACHE
Is there any equivalent in SQL Server for the above (specifically for the NOCAHE syntax)
Please advice,
Thanks,
Sam
View 2 Replies
View Related
Apr 11, 2008
is there a C# equivalent to system_user?
I asked my dev team but they all work from home on Fridays (read sleeping on their couches), and I have not heard back yet.
View 3 Replies
View Related
Nov 16, 2006
...For Oracles DECODE function?
I am trying to get a conditional output RETURNed to the Grid output and have not found it in SQL Help. Help!!!
Here is Oracles example:
Select Distinct City,
DECODE (City, 'Cincinnati', 'Queen City', 'New York', 'Big Apple', 'Chicago',
'City of Broad Shoulders', City) AS Nickname
From Cities;
View 4 Replies
View Related
Dec 18, 2006
jess writes "Hi,
IS there a component/way of retrieving a list of SQL Servers or databases on your local network for SQL 2005/Express. The same way sqldmo worked for a .net project.
thanks"
View 1 Replies
View Related
Feb 15, 2007
Hello,
What is the sql equivalent of to_char?
Here is a line of code I am trying to fix.
ELSE to_char(COMPLET, 'DD-MM-YYYY') end)COMPLETE, DESCRIPTION, NAME, ADDRESS, JOB, TYP, NUM, OPR, sum(QTYW) QTY, sum(NCommissionAUT) CommissionAUT
Is there anything else in this line of code that I might need to change?
Thanks,
Kurt
View 6 Replies
View Related
Feb 22, 2008
Hello,
I'm creating a view in SQL and am looking for something equivalent to the IIF ststement in Access.
Basically I want to create 2 new columns, which are based on the result of 1 of the other columns.
So if in my columns I have :
ID - NAME - FLAG - TIMEFROM - TIMETO
11 - Fred - 0 - 09:00 - 10:30
12 - John - 1 - 11:30 - 15:30
etc, etc, etc
I want to add the first new column saying something along the lines of "If Flag = 0 then DateTo - DateFrom, otherwise Null"
and then add a second column saying "If Flag = 1 then DateTo - DateFrom, otherwise Null"
Therefore the above would show :
ID - NAME - FLAG - TIMEFROM - TIMETO - NEWCOL1 - NEWCOL2
11 - Fred - 0 - 10:00 - 10:30 - 0:30 - Null
12 - John - 1 - 11:30 - 15:30 - Null - 4:00
etc, etc, etc
This in turn would give me 2 new columns which would show value 1 and value 2 - 1 being where the flag is not checked, and 2 being where the flag is checked.
Does this make sense ?
View 8 Replies
View Related
Feb 4, 2006
Hi.I'm a casual sql user. I have found a situation where I need to convert anoracle statement to tsql, one I can just fire off in any sql tool against anms sql server database.I studied the exists statement and I think I understand it somewhat, however Iwas not sure how to get it quite right. If you have an idea and a minute ortwo I'd appreciate any insight or tutorial.insert into authorization (program, optiontitle, usergroup, authorizationid)select 'EVERYWHERE','NAVIGATOR',usergroup, authorizationseq.nextvalfrom allgroups where exists (select * from authorizationwhere authorization.USERGROUP = allgroups.USERGROUP andauthorization.optiontitle = 'READ' and authorization.program = 'EVERYWHERE')I believe that because in my data, three values of usergroup from allgroupsreturn true from the exists, that this is supposed to insert three rows intoauthorization.But I can't figure out what to do about the authorization.nextval.. I triedvarious max(authorization)+1etc but nothing seemed to compile/workthanksJeff Kish
View 6 Replies
View Related
Jun 28, 2006
Hi everyone,Please excuse me if this has been asked before or sounds a bit dim.This is a question asked on another forum but the solutions beingoffered are focussing on programming rather than letting the DB serverdo the work, which I'm not sure is the most efficient solution.However, my confession is I dont use SQL server so can't help themdirectly with the syntax. Hopefully you can help me help them and learna little about SQL Server in the process.Trying to right pad a first name field so the padded string is a totalof 30 chars. It will be output concatenated with the last name field,and each field separated with a "|". So that when output it readssomething like:fname | mylastnameSyntax given was:select id,substring((last_name+','+rtrim(' '+isnull(level,'))+''+rtrim(isnull(first_name,'))+space(30)),1,30)+ ' | ' as student_namefrom studentIssue: It appears this is padding correctly but the spaces are notrendering in the browser. (I have no way to check this as I don't usesqlserver. However, I can understand that multiple spaces are not goingto render in the client browser, if indeed the query is padding withspaces.Question: Instead of using space(), can replicate() be used and aunicode space representation rather than an actual space be used? Or,is there a better way that will ensurethe padding shows in browser?I guess a fixed width font would also need to be used otherwise the30-char blocks could wind up being different widths, which would defeatthe purpose.If there is something I've missed, or you have any suggestions, I'mkeen to learn.TYhanks in advance,Lossed
View 13 Replies
View Related
Nov 27, 2006
Is there an equivalent in mssql to SQL Anywhere's GET_IDENTITY whichreserves the next autoinc value for a table? Yes I know about@@Identity and SCOPE_IDENTITY. I need to get the next autoinc value_before_ I insert the record due to the way the existing applicationworks.I've seen DBCC CHECKIDENT mentioned but that seems kludgy to me.TIA,Jim
View 13 Replies
View Related
Dec 8, 2007
Hi Folks,
Is there any effcent way of copy bulk records from SQL2000 to SDF ? The approach I am using at moment is manually concatenate insert CommandText based on the value datatable from SQL 2000. However, it's not very effcient and I am getting timeout on a table that has around 30 fields and 3,600 records.
Can any one think a better way of doing bulk insert on SDF? Both schema on SQL 2000 and SDF are exactly the same.
Thanks
View 8 Replies
View Related
Oct 3, 2007
I am looking for a way to programatically determine the size of the data contained in a table, much like the sp_spaceused proc in SQL Server.
Thanks.
View 3 Replies
View Related
Aug 22, 2007
I have a query that returns a set of rows - sorted by part#. On the report I can hide the duplicates (part#). How can I test the part# so that whenever a new part# starts I can reverse image the whole l line. I have not defined any groups. Is this a must?
View 2 Replies
View Related
May 15, 2006
Hi All,
I have a table with a count of 30K rows that describe values over a period of time. I would like to be able to replicate the PERCENTILE_CONT function that is found in Oracle with MS SQL Server 2005 but have not had much success.
Would anybody know of a way to use current MS SQL syntax to retrieve the value of the 5th,10th,15th,20th etc... percentile of my table values? Assume that all of the values are associated with the same key. Oracle gives you the Percentile_Cont function for inverse percentile calculation but what does SQL2005 give you?
Sample Table Structure:
ID int, Timestamp datetime, Value int
View 3 Replies
View Related
Jun 19, 2007
Hello All,
In Crystal reports there was a property "New Page after". When this property is checked, a page break is inserted after the section is printed. Is there an equivalent in Reporting services? I am using a Table in the body of the report and i want to insert a page break once 20 rows have been displayed on the report. Please let me know how this could be achieved in reporting services.
Thanks,
RS-2005
View 1 Replies
View Related
Sep 7, 2006
I have several areas where it will either be yes / no or enabled / disabled in the site I am working on. I remember in ACCESS there was a yes no field. Is their an equivalent to this in SQL2005 and if so, what data type should I use. I know this is a simple stupid question, but I am new to SQL and .NET. Thanks in advance for your help!!!
View 3 Replies
View Related
Jan 29, 2008
VWD 2005 Express. Visual Basic. SQL Server 2005.
I have a gridview tied to a sqldatasource. If there have been changes made to the records of the sqldatasource, does a sqldatasource.databind have the effect of requerying the database? Is this the proper method to use if I want to requery/update the gridview form?
View 2 Replies
View Related