Sub-queries Are Not Allowed
May 27, 2015
I want to pass the string "select @@servername" in the print statement, it throws error as:=
Msg 1046, Level 15, State 1, Line 3
Subqueries are not allowed in this context. Only scalar expressions are allowed.
Msg 1046, Level 15, State 1, Line 28
Subqueries are not allowed in this context. Only scalar expressions are allowed.
declare @account_name nvarchar(400) = 'Mail Account';
IF exists (select * from msdb.dbo.sysmail_account where name = @account_name)
PRint 'Database Mail Account ' + quotename (@account_name) + 'is already setup in the Server:= ' + (select @@servername);
I mean why such restriction? In such queries results will be only 1 so it does not violate the SET operation. correct??
View 3 Replies
ADVERTISEMENT
Jan 29, 2007
Hi all,
I need to rewrite the following query without a nested query (stupid mysql 4.0.25. Can anyone lend a hand?
SELECT name from `list` where name not in (
SELECT DISTINCT b.name from ` armor ` a,` list` b where b.name = a.name
);
View 4 Replies
View Related
Sep 18, 2007
Hello,
I have a WCF Windows Service which caches some query results. I am using the SqlDependency class to watch for any data changes in the backend SQL table, and then if so, update the loca caches.
Everything works great, except under concurrent use. If a client of the service runs a job, and at the same exact time, a user using the web application front end updates one of the SQL lookup tables, I get the following SqlClientException from the WCF Service: {"Transaction (Process ID 72) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction."}. I could be wrong on the scenario that causes it, however I believe this is the case.
I'm not sure why this is happening to be honest.. however I have seen this issue in the past and we have solved it by using the 'WITH(NOLOCK)' clause on the query that is causing the error...
I tried simply adding WITH(NOLOCK) to the query that is being watched from inside the WCF Service - however then in my OnChanged event I got errors about the query not being correct. I have gone over the dtails on what invalidates a query for Service Broker (http://msdn2.microsoft.com/en-us/library/aewzkxxh.aspx) and I do not see NOLOCK on the list...
Is there something obvious I'm missing here? More importantly, since it appears this is invalid... what should I do to handle this situation? Can I just handle the SqlException on the client side and then re-try loading the dataset and hooking to OnChanged??
Thanks
View 3 Replies
View Related
Jun 17, 2004
Hi, I was trying to run an insert statement which has subquery, But it is returning the error like this..
Subqueries are not allowed in this context. Only scalar expressions are allowed.
--------------
Is there a way to reparse the insert statement without have to assign the subquery to a temp value and insert it?
thanks..
Here is my SQL..
insert into admincriteria values (nextID,(select id from nodetable where description like 'Example - Quality Analytics'),8071,2,'Failures by Customer',2,0,0)
View 14 Replies
View Related
Feb 6, 2008
I have a sql select statement, then I have a datareader and I'm trying to loop through that reader and insert a record into another table each time until there are no more records in the loop. I'm not sure how to do this though without using 2 datareaders. Please help. Thanks
1 ' Retrieve Data from database based on selections chosen in ListBox
2 Dim cmdCommittee As New SqlCommand("Select * from committees_tbl where committee_id in" & _
3 "(" & strCommitteesRemoveLast & ") order by committee_name", conn_Insert)
4
5 ' setup a datareader
6 Dim drCommittee As SqlDataReader = cmdCommittee.ExecuteReader()
7
8
9 ' Loop through datareader and insert rows
10 ' into the xref_person_committees_tbl
11 While drCommittee.Read()
12 Dim strCommitteeName As String = drCommittee("committee_name") 'retrieve committee_name from datareader
13
14 ' Create a sql string
15 Dim strAddCommittee As String = String.Empty
16 strAddCommittee = "Insert into xref_person_committees_tbl (committee_name) values ('" & strCommitteeName & "')"
17 'Response.Write(strAddCommittee & "<br>")
18
19 ' Create a sql command to process the insert
20 Dim sqlAddCommittee As New SqlCommand(strAddCommittee, conn_Insert)
21 Dim drNewCommittee As SqlDataReader = sqlAddCommittee.ExecuteReader()
22
23
24
25
26 End While
27 ' -----------------------------------------------------------------------------------
28
29 drCommittee.Close()
View 5 Replies
View Related
Apr 13, 2006
I want to put some trace in the a UDF, so I put print in the function. IT gave error. Can anyone please explain why this happen. But this work with SPs.
Cheers
Shimit
View 1 Replies
View Related
Feb 9, 2006
Hi
Keep getting this message in the Application Event Viewer.
Source: SQLAgent$SHAREPOINT
Category: Alert Engine
Event ID: 324
Description: SQLAgent is not allowed to run.
Can't find any help online. Anyone out there got any ideas?
TIA
View 5 Replies
View Related
Aug 17, 2007
Hi everyone,
I was browsing and came across this code with this result set
CREATE TABLE dbo.SalesByQuarter
(
Y INT,
Q INT,
sales INT,
PRIMARY KEY (Y,Q)
)
GO
INSERT dbo.SalesByQuarter(Y,Q,Sales)
SELECT 2003, 2, 479000
UNION SELECT 2003, 3, 321000
UNION SELECT 2003, 4, 324000
UNION SELECT 2004, 1, 612000
UNION SELECT 2004, 2, 524000
UNION SELECT 2004, 3, 342000
UNION SELECT 2004, 4, 357000
UNION SELECT 2005, 1, 734000
GO
SELECT Y,
[1] AS Q1,
[2] AS Q2,
[3] AS Q3,
[4] AS Q4
FROM
(SELECT Y, Q, Sales
FROM SalesByQuarter) s
PIVOT
(
SUM(Sales )
FOR Q IN ([1],[2],[3],[4])
) p
ORDER BY
GO
DROP TABLE dbo.SalesByQuarter
GO
Y Q1 Q2 Q3 Q4
2003 NULL 479000 321000 324000
2004 612000 524000 342000 357000
2005 734000 NULL NULL NULL
I tried to modify it to remove the nulls by changing this line of code
SUM( ISNULL(Sales,0))
I got this error
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'ISNULL'.
so i tried it like this
and got this error
Msg 195, Level 15, State 1, Line 12
'ISNULL' is not a recognized aggregate function.
My question is why can't i use isnull to change NULL TO 0
Thanx
Slimshim
View 8 Replies
View Related
Aug 9, 2006
Could someone please tell WHY it is not allowed to use the following construction in a stored procedure!?
AS IF @taxparent = 0 THEN SET @taxparent = NULL IF @museum = 0 THEN SET @museum = NULL IF @collection = 0 THEN SET @collection = NULL SELECT ID, SpecimenNr, ScientificName, Locality, Taxon FROM QueryView
I get the following error messsages:
Msg 156, Level 15, State 1, Procedure DynamicQuery, Line 9Incorrect syntax near the keyword 'THEN'.Msg 156, Level 15, State 1, Procedure DynamicQuery, Line 10Incorrect syntax near the keyword 'THEN'.Msg 156, Level 15, State 1, Procedure DynamicQuery, Line 11Incorrect syntax near the keyword 'THEN'
Any help is greatly appreciated!
View 3 Replies
View Related
Dec 1, 2006
I am using the SQLEXPRESS database, and connect from to locations:
Windows Service
ASP.NET web application.
whenever I start the windows service I get the error: Cannot open user default database. Login failed.
so I am going to visual studio and close the connection. then I close the web browser, and the windows service succeed connect to database.
but then, after windows service is connected, I open the web browser application and fails to login because the login system using the same database of windows service, and since the connection is being used by windows service, login is impossible.
Do you know how I can allow 2 connections at the same time for the same database?
what are the risks to do that? and how do I handle this risks.
thanks alot
View 3 Replies
View Related
May 13, 2002
Can anyone tell me what is the maximum number of rows that I can code in a T-SQL step if I want to
include this in a job? I do not want to use stored procedure for certain task, so I want to put the same code in a T-SQL step.
Thanks!
Sheila.
View 1 Replies
View Related
Feb 23, 2005
Hello,
I need to know what kind of characters are NOT allowed in SQL literals and the way(s) to go around it.
In example:
Code:
' must be replaced by ''
I would greatly appreciate all the help you guys can provide me with.
Thank you for taking the time.
View 2 Replies
View Related
Feb 6, 2007
I entered the max 8000 varchar in a column and it will not let me enter more than about 1000. What is the deal?
thanks
Matt
View 8 Replies
View Related
Feb 20, 2007
Um, still trying to transpose MySQL into T-SQL.
Inserting info into a table, where one of the columns meets a certain criteria.
insert into employee (/*emp_id,*/ fname, lname, start_date,
dept_id, title, assigned_branch_id)
values (/*null,*/ 'Michael', 'Smith', '2001-06-22',
(select dept_id from department where name = 'Administration'),
'President',
(select branch_id from branch where name = 'Headquarters'));
But I'm getting this error:
Msg 1046, Level 15, State 1, Line 5
Subqueries are not allowed in this context. Only scalar expressions are allowed.
Any help would be greatly appreciated.
View 2 Replies
View Related
Nov 27, 2007
For example I have
CASE (a.t_id)
WHEN (a.t_id in (22,23,27,30,38))
THEN t.desc
ELSE 'N/A'
END 'Column name..',
and that is giving me "incorrect syntax near 'in'" ??
View 20 Replies
View Related
Jul 23, 2005
I am trying to make the following SQL statement, but there seems to a limiton how long a statement can be:INSERT INTO CUSTOMER (forename, surname, company_name, title, addressA,addressB, postal_number, city, country, home_phone, mobile_phone,work_phone, fax, email, sale_procentage, bank, account_number,creation_initials, creation_date, creation_reason) values ("test", "test","test", etc...);But I can only enter this much text:INSERT INTO CUSTOMER (forename, surname, company_name, title, addressA,addressB, postal_number, city, country, home_phone, mobile_phone,work_phone, fax, email, sale_procentage, bank, account_number,creation_initials, creation_date, creation_reason) vaIs there some upper limit? And how do I make a long SQL statement like this?JS
View 1 Replies
View Related
Jul 20, 2005
I have a simple table, for some reason, certain columns seem to acceptNulls even though they shouldn't, for example the I can set the 'Name'field to Null using my web application or directly in EnterpriseManager. field How do I prevent this? However the 'RecCreated' doessnot permit nulls.CREATE TABLE [dbo].[Group] ([GroupID] [int] IDENTITY (1000, 1) NOT NULL ,[Name] [nvarchar] (50) NOT NULL ,[Description] [nvarchar] (750) NULL ,[RecCreated] [datetime] NOT NULL ,[RecUpdated] [datetime] NOT NULL ,[RecCreatedBy] [int] NOT NULL ,[RecUpdatedBy] [int] NOT NULL ,[RecActive] [int] NOT NULL) ON [PRIMARY]GOthanks for any help you can give on this
View 7 Replies
View Related
Feb 14, 2008
Working on partitioning a few large tables. One of the tables included a text column and the €œTEXTIMAGE_ON [PRIMARY]€? clause which would prevent the partitioning of this table. After some research we found that the data was legacy and no longer used. We updated the column on the affected rows to NULLS and altered the column to a VARCHAR(20)
I then attempted to run the ALTER TABLE SWITCH and I encountered the error
Msg 4947, Level 16, State 1, Line 1
ALTER TABLE SWITCH statement failed. There is no identical index in source table 'LocalDeltanet.dbo.testresultsjoe' for the index 'PKIDX_testSummary' in target table 'LocalDeltanet.dbo.testresults_part'.
After a lot of grief and testing I determined that the message was bogus and the real issue is that the 'sys.tables' still has €œlob_data_space_id€? with a value of 1 for this table.
I created a copy of the table with the text column and the "TEXTIMAGE_ON", then altered the column to a varchar and another table with just the varchar column and no "TEXTIMAGE_ON" spoecified. After copying the data from the original table, I tried to run the Alter Switch. It failed once again for the table with the text column that was altered to varchar, but it worked for the table that had the column specified as varchar from the start.
All other things have been checked and the two source tables in this test are identical execpt for the Text column specification. The alter column changes the definition of the column, but how would you remove the €œlob_data_space_id€? setting, since it appears that this value is causing my issues, is there anyway to update the table in place. I know I can BCP the data out, but that would take too long and would defeat the advantage of using the alter switch method.
BOL States:
The allow updates option is still present in the sp_configure stored procedure, although its functionality is unavailable in Microsoft SQL Server 2005 (the setting has no effect). In SQL Server 2005, direct updates to the system tables are not supported. This means we cannot update the table manually.
View 1 Replies
View Related
Apr 15, 2008
Hi, I've read that a SQL Server Express database is limited to GB. If I have a database with about 120 tables which store only simple datatypes (int, money, datetimes, varchar, etc.), no blobs or large files, how can I estimate the amount of data or number of rows it can hold before it runs out?
View 11 Replies
View Related
Jul 25, 2006
Just installed SQL Express but cannot connect since it says Remote Connections are not allowed ! This worked before. I have tried different protocols and even SQL Authentication. No luck here and I've been up all night...
View 5 Replies
View Related
Jul 2, 2006
I have a form to submit some data to a database located in the App_Data folder. I have the following connection string:
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|Siven.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
On the form I'm using a DetailsView control and using a SqlDataSource as the datasource, pointing to the above connection string. In realtime, when i submit the data, I receive the following error:
Server Error in '/' Application.
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I'm using discountasp.net as the host, and I did not elect to use the SQL Server databases, I'm just going to use SQL 2005 express. I dont understand why it's not pointing to the db when it's there (and to make sure, I re-uploaded). Is there something I missed here?
View 1 Replies
View Related
Oct 25, 2007
Hi,
I have a wierd error occuring here.
<compilers>Line 95: <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4" compilerOptions="/warnaserror-">Line 96: <providerOption name="CompilerVersion" value="v3.5"/></compiler>Line 97: <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" compilerOptions="/optioninfer+">Line 98: <providerOption name="CompilerVersion" value="v3.5"/></compiler></compilers></system.codedom>
Can someone help me about this one
View 2 Replies
View Related
Jan 16, 2006
I've created a new website using the new Visual Studio 2005 Express edition. This site uses SQL Server Express (free software) as a storage for personalization data, etc. Now I want to deploy my site, but here it ends for me:My web site hoster does not support the SQL Express edition in a shared hosting environment. I think most people have a website running in a 'shared hosting' plan. How can this large group enjoy the new Express line when SQL Server Express is not supported? "SQL Server Express is not a part of the SPLA SPUR (Services Provider License Agreement)", they all say. Here it ends for me, my ISP and their licence supplier. Even at Microsoft's Response Management Team, 'no' is the answer.
What to do now? Move on to an expensive 'dedicated hosting' plan? Write a membershipprovider for MySQL?I feel as if I was given a free ticket for a nice journey but there's no traffic possible.
Who can help me out here? What can I do...
View 15 Replies
View Related
Dec 4, 2007
Hi,
I'm wondering if SqlCommand.CommandText could be set with multiple statements when CommandType=Text. anyone knows it?
I'm sure storedprocedure is the right way to go. I'm curious if this is one thing that only sp can do.
Thx
Tao
View 1 Replies
View Related
Jan 26, 2008
Hi, my problem is:
When Im trying to connect my my SQL server, this comes:
Host >compname< is not allowed to connect to this MYSQL server
how do I fix it?
View 1 Replies
View Related
Aug 24, 2005
Hi all, I am brandnew with SQL2000, so sorry in advance forstupidities....SQL2000, SP3, running on a SBS2003-server with WindowsSharePointServices.I want to make a dataconnection (from within the LAN with InfoPath) froma client to this server. I got the error that whether the server doesnotexists (it does) or no permission. Where can I find (in SQL2000) whichusers have access to the databases ???Help is appreciated, Ger.*** Sent via Developersdex http://www.developersdex.com ***
View 2 Replies
View Related
May 13, 2008
Afternoon,
Can anyone relay to me if there is a max number of elements that are allowed within an IN clause?
Example would be:
SELECT * FROM tblMyTable WHERE ID_Number IN (1,2,3,4,5,...150,000)
where we list all 150,000 numbers between the ( ).
Thanks!
View 4 Replies
View Related
Aug 7, 2007
I have this stored procedure on SQL 2005:
USE [Eventlog]
GO
/****** Object: StoredProcedure [dbo].[SelectCustomerSoftwareLicenses] Script Date: 08/07/2007 16:56:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SelectCustomerSoftwareLicenses]
(
@CustomerID char(8)
)
AS
BEGIN
DECLARE @Temp TABLE (SoftwareID int)
INSERT INTO @Temp
SELECT SoftwareID FROM Workstations
JOIN WorkstationSoftware ON Workstations.WorkstationID = WorkstationSoftware.WorkstationID
WHERE Workstations.CustomerID = @CustomerID
UNION ALL
SELECT SoftwareID FROM Notebooks
JOIN NotebookSoftware ON Notebooks.NotebookID = NotebookSoftware.NotebookID
WHERE Notebooks.CustomerID = @CustomerID
UNION ALL
SELECT SoftwareID FROM Machines
JOIN MachinesSoftware ON Machines.MachineID = MachinesSoftware.MachineID
WHERE Machines.CustomerID = @CustomerID
DECLARE @SoftwareInstalls TABLE (rowid int identity(1,1), SoftwareID int, Installs int)
INSERT INTO @SoftwareInstalls
SELECT SoftwareID, COUNT(*) AS Installs FROM @Temp
GROUP BY SoftwareID
DECLARE @rowid int
SET @rowid = (SELECT COUNT(*) FROM @SoftwareInstalls)
WHILE @rowid > 0 BEGIN
UPDATE SoftwareLicenses
SET Installs = (SELECT Installs FROM @SoftwareInstalls WHERE rowid = @rowid)
WHERE SoftwareID = (SELECT SoftwareID FROM @SoftwareInstalls WHERE rowid = @rowid)
DELETE FROM @SoftwareInstalls
WHERE rowid = @rowid
SET @rowid = (SELECT COUNT(*) FROM @SoftwareInstalls)
END
SELECT SoftwareLicenses.SoftwareID, Software.Software, SoftwareLicenses.Licenses, SoftwareLicenses.Installs FROM SoftwareLicenses
JOIN Software ON SoftwareLicenses.SoftwareID = Software.SoftwareID
WHERE SoftwareLicenses.CustomerID = @CustomerID
ORDER BY Software.Software
END
When i execute it in a Query in SQL Studio it works fine, but when i execute it from an ASP page, i get following error:
ADODB.Recordset error '800a0e78'
Operation is not allowed when the object is closed.
/administration/licenses_edit.asp, line 56
Here the conection:
Set OBJdbConnection = Server.CreateObject("ADODB.Connection")
OBJdbConnection.ConnectionTimeout = Session("ConnectionTimeout")
OBJdbConnection.CommandTimeout = Session("CommandTimeout")
OBJdbConnection.Open Session("ConnectionString")
Set SQLStmt = Server.CreateObject("ADODB.Command")
Set RS = Server.CreateObject("ADODB.Recordset")
SQLStmt.CommandText = "EXECUTE SelectCustomerSoftwareLicenses '" & Request("CustomerID") & "'"
SQLStmt.CommandType = 1
Set SQLStmt.ActiveConnection = OBJdbConnection
RS.Open SQLStmt
RS.Close
Can anyone help please?
It this because of the variable tables?
View 7 Replies
View Related
Jan 11, 2007
I am getting this exception in RC1:
SqlCException: Duplicated parameter names are not allowed. [ Parameter name = @SOLUTIONID ]
With the following statement:
SELECT [VERSIONID], [SOLUTIONID], [BASEVERSIONID], [VERSIONNUMBER], [NAME], [DESCRIPTION], [CREATEDATE], [UPDATEDATE], [VERSIONCLOSED] FROM VERSIONS WHERE SOLUTIONID = @SOLUTIONID AND VERSIONCLOSED = 1 AND VERSIONID IN (SELECT MAX(VERSIONID)
FROM VERSIONS WHERE SOLUTIONID = @SOLUTIONID);
Besides the obvious of adding a new parameter with the same value and a different name - are there any plans to fix this?
Another area where SQLCE seems deficient is non-support of SCOPE_IDENTITY(), which although not important for CE itself is very important for TSQL compatibility with SQL Server - where obviously @@IDENTITY won't cut it.
A related problem to this is that SQL CE doesn't support batch statements - which sadly destroys the useful pattern of inserting a record with an INSERT and doing an identity SELECT in the same batch.
View 4 Replies
View Related
Sep 23, 2007
I'm connecting to an Sql Compact database (3.1) from a C# assembly exposed via COM and called from inside a winsock LSP. The database is only used once on instantiation of the class, which happens in the first call to WSPStartup.
The issue I'm having is that under Vista and when running inside IE7 I get the error in the title. However there is no problems with IE7 under windows XP, or with Firefox and MSN Messenger under XP or Vista!
When selecting to run IE as administrator, the problem dissapears, however when using the LogonUser API to impersonate an administrator it doesnt.
This would seem like a permissions issue, strange though that Firefox under vista has no problems.. Also, the following code throws no SecurityException under either browser, indicating the code is running with full trust.
new PermissionSet(PermissionState.Unrestricted).Demand();
Any input would be a huge help, I've been banging my head against this all day..
View 4 Replies
View Related
Apr 10, 2008
Dear Sirs.
I have Written WinForm Application that uses SQL Server Compact 3.5.
I also deploy Database (SDF) File with this application.
Installation Package Created Using InstallShield 2008.
I Deployed SDF in Common App Data Folder. In Administrator mode Application is working fine.
But in User Mode I Get Error Message.
"Access to the database file is not allowed.
[ File name = C:Documents and SettingsAll Users
Application DataGeorgian MicrosystemsCodex 2007 R2 Russian
DatabaseCodexRussian2007.sdf ]"
I Also Tested That Application in user mode Can Create File in ("C:Documents and SettingsAll Users
Application DataGeorgian MicrosystemsCodex 2007 R2 Russian
Database") Directory.
Test Environment is XP SP2
I Tryed to Copy SDF file manualy. Appplication in user mode can access on it if file is copyed in user mode.
if this file is copyd in Administator mode even in users Local Directory SQL Engine can't access on it.
Please Help me to Slove this problem.
How to connect using user mdoe to SDF deploed with admin right. (MSI installer).
Thank you in advance.
View 1 Replies
View Related
Sep 16, 2005
in SQLServer2005 how can I allow update system catalogs (by mouseclick)?
View 59 Replies
View Related
Oct 25, 2006
I have a Windows 2003 64-bit server running SQL 2005. I am trying to run an OpenRowSet query, but I am getting ""cannot create instance of linked server" (null)" The OpenRowSet I am trying to run was running perfectly fine on the same machine before we moved to SQL 2005 and runs fine on many other machines - so I do not think it is an issue with the openrowset itself.
When I've had his issue on other machines, I have run the following:
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure €˜Ad Hoc Distributed Queries€™, 1;
GO
RECONFIGURE;
GO
And I could then run the Ad Hoc queries fine. But, when I try on this machine, I get the SQL error message:
"The configuration option does not exist, or it may be an advanced option."
I looked at the settings in SQL Server Surface Area Configuration and Ad Hoc was selected; so it should be working. I am logged in as Administrator and have sysAdmin permissions in the SQL database. I'm not sure where else to look or what I am missing.
I've looked many places on the web and have tried many 'solutions' without effect.
Any thoughts??
View 5 Replies
View Related