This runs in Access, but SQL Server 7 complains that BETWEEN is unrecognized. Can anyone help me? thanks
SELECT yearId, IIf(Date() BETWEEN [qrtOneStart] AND [qrtOneEnd],1, IIf(Date() BETWEEN [qrtTwoStart] AND [qrtTwoEnd], 2, IIf(Date() BETWEEN [qrtThreeStart] AND [qrtThreeEnd], 3, 4))) AS CurrentQrt, yearName
FROM tblYear
I know how to access different tables on the same server by prefixingthe table with the database name. Is there anyway to prefix theserver name to link two tables across servers? Thanks.
) ) ) ) ) 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.
Hi guys! I am using SQL 2005 and I wonder why I am encountering the error "[Microsoft][ODBC SQL Server Driver]Syntax error or access violation" everytime I am trying to create stored procedure with temp table and table variable. See my code below with temp table.
Any thoughts will be appreciated!
CREATE PROCEDURE DBO.SAMPLESP (@DETAILS AS VARCHAR(8000), @ID AS VARCHAR(15))
AS
BEGIN TRANSACTION
CREATE TABLE DBO.#TEMPTABLE { ASSET VARCHAR(50) }
DECLARE @INSTINSERT AS NVARCHAR(4000) SET @INSTINSERT= 'INSERT INTO #TEMPTABLE(ASSET)' SET @INSTINSERT= @INSTINSERT+ @DETAILS
EXEC sp_ExecuteSQL @INSTINSERT
INSERT INTO InstDetail (TrackNum, ASSETID) SELECT @ID, A.ASSE FROM #TEMPTABLE A
DROP TABLE #TEMPTABLE
IF @@ERROR != 0 BEGIN ROLLBACK TRANSACTION RAISERROR('There was an error in here', 11, 1) RETURN END ELSE COMMIT TRANSACTION
There is a JOIN syntax error in this SQL, but my slow brain cannot figure out where. I tried to join two queries, which had been successful. Problem occurred when I added second left join. Can anyone help?
PARAMETERS pstrFinYear Text ( 255 ), pintAdjMonth Long;
SELECT A.BudgetLineID, A.BudgetLine, B.NumIsDevelopBusinessInternationally, B.NumIsDeeperParticipation, B.NumIsNewExporter, B.NumProjects, C.NumCompanies, A.KMISReportOrder FROM ( tblkpBudgetLine AS A
LEFT JOIN
[SELECT BudgetLineID, FinancialYear, SUM(IsDevelopBusinessInternationally) AS NumIsDevelopBusinessInternationally, SUM(IsDeeperParticipation) AS NumIsDeeperParticipation, (-1*SUM(AdjustedNewExpMonth=pintAdjMonth)) AS NumIsNewExporter, COUNT(ProjectID) AS NumProjects FROM qryBoardReport_Actuals WHERE FinancialYear=pstrFinYear AND AdjustedProjectStartMonth=pintAdjMonth GROUP BY BudgetLineID, FinancialYear]. AS B ON (A.BudgetLineID=B.BudgetLineID) AND (A.FinancialYear=B.BudgetLine)
LEFT JOIN
[SELECT Z.BudgetLineID, Z.FinancialYear, Z.AdjustedProjectStartMonth, COUNT(Z.Company) AS NumCompanies FROM [SELECT DISTINCT qryBoardReport_Actuals.BudgetLineID AS BudgetLineID, qryBoardReport_Actuals.FinancialYear AS FinancialYear, qryBoardReport_Actuals.AdjustedProjectStartMonth, qryBoardReport_Actuals.CompanyID as Company FROM qryBoardReport_Actuals WHERE FinancialYear=pstrFinYear AND AdjustedProjectStartMonth=pintAdjMonth GROUP BY qryBoardReport_Actuals.FinancialYear, qryBoardReport_Actuals.BudgetLineID, qryBoardReport_Actuals.AdjustedProjectStartMonth, qryBoardReport_Actuals.CompanyID]. AS Z GROUP BY FinancialYear, BudgetLineID, AdjustedProjectStartMonth] as C
ON (A.BudgetLineID=C.BudgetLineID) and (A.FinancialYear=C.FinancialYear))
WHERE A.FinancialYear=pstrFinYear ORDER BY A.KMISReportOrder;
I created a couple of stored procedures. One of them (let's call it SP1) dumps information into a table and then calls another stored procedure (SP2) to put the info in a temp table in crosstab format. SP1 then displays the info from the temp table.
When I execute SP1 from Query Editor, everything works perfectly. No errors are returned and my data is displayed just as expected.
When I try to execute SP1 from MS Access's pass-through query, I get the following error:
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near ','.(#102)[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'A'(#102)
I've found that the error occurs when the SP2 is called from within SP1. If it's working fine in Query Editor, shouldn't it work from MS Access? Any insights?
I have used this query statement with a SQL Server 2005 database and need to use something similar with an Access database:
SELECT products.*, Category AS Expr1 FROM products WHERE (Category = @Category)
When I test this in a table adapter there is no preview due to lack of parameter. I seem to recall that Access uses different syntax in the WHERE filter clause (i.e., not @). Can someone help me out with this?
I am having trouble finding the correct syntax to access a variable. I have a variable defined in the Variables window: The variable name is formatedDate. The DataType is String.
I am successfully setting the value of the variable in a Execute SQL Task. The SQL is as follows:
SELECT LEFT(CONVERT(VARCHAR, MAX(ReportDate), 120), 10) as formatedDate from DimReportDates
The Result Set is set to “Single Row” and properly set up.
No problem so far. I can see with a watch that the variable has the correct value, something like:
‘2015-09-30’
Now, in a subsequent step, a Data Flow Task, I want to access the variable. Actualy it is in the SQL statement of a OLE DB source in the Data Flow… I have the following:
MS SQL Server 2005 Express. I'm trying to connect to Access DB (having System Database) via OPENROWSET. Everything (client, server and access file) is on local drive.
This works (ODBC):
select * from openrowset('MSDASQL', 'Driver={Microsoft Access Driver (*.mdb)};Dbq=C:MBK.mdb;SystemDB=C:SECURED.MDW;Uid=me;Pwd=pw;', 'select * from [Mbk]')
This works (Jet.OLEDB):
select * from opendatasource('Microsoft.Jet.OLEDB.4.0', 'Data Source=C:MBK.mdb;Jet OLEDBystem Database=C:SECURED.MDW;User ID=me;Password=pw;') ...Mbk
This won't work (Jet.OLEDB):
select * from openrowset('Microsoft.Jet.OLEDB.4.0', 'MS Access;Database=C:MBK.mdb;System Database=C:SECURED.MDW;UID=me;PWD=pw;', 'select * from [Mbk]')
saying ... "Wrong argument".
This won't work (Jet.OLEDB):
select * from openrowset('Microsoft.Jet.OLEDB.4.0', 'MS Access;Database=C:MBK.mdb;SystemDB=C:SECURED.MDW;UID=me;PWD=pw;', 'select * from [Mbk]')
saying ... "There are no permissions for usage of object C:MBK.mdb". It seems that it simply hasn't found system database file C:SECURED.MDW, cause when I change SystemDB=C:SECURED.MDW to something like BlahBlahBlah=C:SECURED.MDW the same message is shown.
So, what is the right syntax for stating System Database in OPENROWSET query string? And why 'System Database' won't work?
Hi, I'm having an SSIS package which gives the following error when executed :
Error: 0xC002F210 at Create Linked Server, Execute SQL Task: Executing the query "exec (?)" failed with the following error: "Syntax error or access violation". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.Task failed: Create Linked Server
The package has a single Execute SQL task with the properties listed below :
General Properties Result Set : None
ConnectionType : OLEDB Connection : Connected to a Local Database (DB1) SQLSourceType : Direct Input SQL Statement : exec(?) IsQueryStorePro : False BypassPrepare : False
Parameter Mapping Properties
variableName Direction DataType ParameterName
User::AddLinkSql Input Varchar 0
'AddLinkSql' is a global variable of package scope of type string with the value Exec sp_AddLinkedServer 'Srv1','','SQLOLEDB.1',@DataSrc='localhost',@catalog ='DB1'
When I try to execute the Query task, it fails with the above error. Also, the above the sql statement cannot be parsed and gives error "The query failed to parse. Syntax or access violation"
I would like to add that the above package was migrated from DTS, where it runs without any error, eventhough it gives the same parse error message.
I would appreciate if anybody can help me out of this issue by suggeting where the problem is.
Hi, I'm writing a stored procedure and when I click on the Check Syntax button its giving me the error in the subject. I'm not really sure whats wrong with this. Here is my Stored Procedure code. Any help wud be appreciated.
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
Dim myConnection As New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("connectionstring")) Dim cmdSQL As New SqlCommand(strSQL, myConnection)
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?
I have recently upgraded to SQL2014 on Win2012. The Access front end program works fine.
But, previously created Excel reports with built in MS Queries now fail with the above error for users with MS 2013. The queries still work for users still using MS 2007.
I also cannot create any new queries and get the same error message. If I log on as myself on the domain to another PC with 2007 installed it works fine, so I don't think it is anything to do with AD groups or permissions.
I've been developing desktop client-server and web apps and have used Access and SQL Server Standard most of the time. I'm looking into using SQL CE, and had a few questions that I can't seem to get a clear picture on:
- The documentation for CE says that it supports 256 simultaneous connections and offers the Isolation levels, Transactions, Locking, etc with a 4GB DB. But most people say that CE is strictly a single-user DB and should not be used as a DB Server. Could CE be extended for use as a multi-user DB Server by creating a custom server such as a .NET Remoting Server hosted through a Windows Service (or any other custom host) on a machine whereby the CE DB would run in-process with this server on the machine which would then be accessed by multiple users from multiple machines?? Clients PCs -> Server PC hosting Remoting Service -> ADO.NET -> SQL CE
- and further more can we use Enterprise Services (Serviced Components) to connect to SQL CE and further extend this model to offer a pure high-quality DB Server? Clients PCs -> Server PC hosting Remoting Service -> Enterprise Services -> ADO.NET -> SQL CE
Seems quite doable to me, but I may be wrong..please let me know either ways
When i am trying to start our hospital software based on SQL server 2000, it shows Following Error.Search Condition is not valid, (DBNETLIB) Connection Open (connect()). SQL server does not exist or excess denied. Due to Fetch data.I run our software in Windows 8.1, while it smothly runs in previous version of Windows XP and 7.
Hello allWould it be possible to migrate the MS Access 2000 to MS SQL Server2000?My application is using MS Access 2000 as database and as userinterface such as forms. Now, I want to migrate the backend databasefrom MS Access 2000 to MS SQL Server 2000. However, I want to keep theMS Access 2000 interface. Would it be possible?If I migrate the MS Access to SQL Server, would the queries, back-endVBA, macro, tables and forms be affected? Do I need to change the MSAccess data type to SQL server supported data type?Which tool I can use to do the migration? Upsizing wizard or exportingthe Access database and then importing it to the SQL server?Thanks in advanceCheersBon
I am trying to connect through ODBC connectivity, but it will not allow me to do so. I have investigated this matter. It leads me back to the server, because as I was configuring my client side database. It kept asking for the DSN(datasource name), but I was unable to choose one because there wasn't one to choose. Which is my current dilemma, How can I do this and have it available to choose from the server to satisfy the Access database?
I went to the domain where the software resides but I don't know what steps to take? I also found an interesting piece on microsoft about Kerberos, but I can't follow along according to the instructions it has. I have Access 2003 & SQL SERVER 2005, HELP...!
Basically, this is right off the heels of the install. I setup the server without the connectivity, but it is running the current configuration.
Hi,I have an issue with my query.1. I have 1 stored proc which have execution calls to multiple storedprocs within it.2. I want to wrap that main stored proc in the transaction and rollbackif there are errors execution calls to other stored procs. I don'tbelieve my code is accounting for errors occuring in the executionstatement to other stored proc.3. Is there an easy way to do this without creating tranaction on eachstored proc and returning the error code? How do I make this happen?Below is the code.Thanks:DALTER procedure spAG_Add_Product@prodCostmoney,@prodWeightdecimal,@prodDescnvarchar(100),@prodNamenvarchar(50),@prodSizenvarchar(100),@pic_filenamenvarchar(50),@userIdint,@exhib_idintASdeclare @auth_Logic_idintdeclare @intErrorCodeintBEGIN TRANSELECT @auth_Logic_id= AG_Auth_Logic.Auth_Logic_ID FROMAG_Auth_LogicINNER JOIN AG_Base_Active_State ON AG_Auth_Logic.Base_Active_State_ID= AG_Base_Active_State.Base_Active_State_IDWHERE AG_Auth_Logic.Action_Description LIKE N'%category%'AND AG_Base_Active_State.Is_Alive = 1INSERT INTO AG_Individual_Product(Product_cost,Product_weight,Product_description,Product_name,User_ID,Auth_Logic_Id,Product_size)VALUES (@prodCost,@prodWeight,@prodDesc,@prodName,@userId,@auth_Logic_id,@prodSize)declare @prod_idintselect @prod_id = Scope_identity()-- add to pic tabledeclare @pic_id_outintexec spAG_Add_Picture @pic_filename,@prodName, @pic_id = @pic_id_outoutputdeclare @prod_pic_outint-- add to product_pic tableexec spAG_Add_Product_Picture @pic_id_out,@prod_id, @prod_pic_id = @prod_pic_out output-- add to product_pic_in_exhibexec spAG_Add_Product_Picture_in_Exhibition @prod_pic_out,@exhib_id, @prod_idselect @prod_idSELECT @intErrorCode = @@ERRORIF (@intErrorCode <> 0) GOTO PROBLEMCOMMIT TRANPROBLEM:IF (@intErrorCode <> 0) BEGINROLLBACK TRANEND
I am not sure why this is producing a SQL Server related error, but w/ohaving an instance of SQL Server on my machine to verify anything further,can you all help me with this?<!--- validate() ---><cffunction name="validate" access="remote" returnType="numeric"><cfargument name="username" required="yes" type="string" /><cfargument name="password" required="yes" type="string" /><cfquery name="validate" datasource="#request.dsn#">SELECT userIDFROM UserWHERE username = '#UCase(username)#'AND password = '#UCase(password)#'</cfquery><cfif validate.RecordCount EQ 0><cfquery name="log" datasource="#request.dsn#">UPDATE UserSET lastLoggedIn = #createOdbcDate(now())#WHERE userId = #validate.userID#</cfquery><cfreturn validate.userID /><cfelse><cfreturn 0 /></cfif></cffunction>Sorry that's all I can honestly provide, other than the error being on theline with <cfif validate.RecordCount>Phil
Hi,I'm new to ASP and have stumbled across what appears to be a commonproblem, but after trying several solutions from other posts I've hadno luck. My SQL SELECT statement is fine elsewhere (e.g. in ACCESS),but when executed from ASP I get this syntax error:Error Type:Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrectsyntax near '16'./forecast/test.asp, line 27(line 27 is where the date is in the HAVING part of the statement)Here is the Statement:----------------------SELECT dbo_ForecastIn.DataTime AS E_Time, dbo_ForecastInData.DataTimeAS FD_Time, dbo_ForecastInData.WindFarmPower AS ForecastPower FROMdbo_ForecastIn INNER JOIN dbo_ForecastInData ON dbo_ForecastIn.DataID= dbo_ForecastInData.DataID GROUP BY dbo_ForecastIn.DataTime,dbo_ForecastInData.DataTime, dbo_ForecastInData.WindFarmPower HAVINGdbo_ForecastIn.DataTime = #06/02/2004 16:00:00# ORDER BYdbo_ForecastIn.DataTime, dbo_ForecastInData.DataTime;Here is the code:-----------------SQLStmt = "SELECT dbo_ForecastIn.DataTime AS E_Time,dbo_ForecastInData.DataTime AS FD_Time,dbo_ForecastInData.WindFarmPower AS ForecastPower "SQLStmt = SQLStmt & "FROM dbo_ForecastIn INNER JOINdbo_ForecastInData ON dbo_ForecastIn.DataID =dbo_ForecastInData.DataID "SQLStmt = SQLStmt & "GROUP BY dbo_ForecastIn.DataTime,dbo_ForecastInData.DataTime, dbo_ForecastInData.WindFarmPower "SQLStmt = SQLStmt & "HAVING dbo_ForecastIn.DataTime = #06/02/200416:00:00# "SQLStmt = SQLStmt & "ORDER BY dbo_ForecastIn.DataTime,dbo_ForecastInData.DataTime;"response.write(SQLStmt)Set RS = Connection.Execute(SQLStmt)Hope one of you geniuses can sort me out.Thanks.
Hi, I've been tasked with investigating how we can migrate from oracle to sql server. I have successfully converted a typical schema with 97% success using SSMA and have a query regarding ADO and oracle syntax.
I have heard that the SQL server provider can interpret oracle syntax into its own syntax, but i am unable to find any reference/examples on the web. Is this possible? and if so could any kind soul please post some links.
if(@b='1') begin select * into #example from example select * from #example drop table #example end else begin select * into #example from example select * from #example drop table #example end With syntax check, I always get "'#example already exist'" But why? Just because of two "select into temp table" operation? I am confused. Thank you.