.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Sub Query Syntax

Posted By:      Posted Date: September 01, 2010    Points: 0   Category :Sql Server
Hi All, I know this is a repost but I have struggled though it and managed to nut most of the issues from this query. An issue I am still getting are multiple values returned by a sub query... Which one SQL doesn't like to clue me into. Below is the stored procedure and I know it is mess, this is reverse engineering a terrible application.   USE [CMI] GO /****** Object: StoredProcedure [dbo].[CMIReport] Script Date: 09/02/2010 09:49:11 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROC [dbo].[CMIReport] @startdate datetime, @enddate datetime as BEGIN ---- ~This drops the tables created by the report before recreating it~ ---- DROP TABLE CMI_Report DROP TABLE CMI_Report_Final_Data ---- ~This Query defines the dates early on in the procedure~ ---- SET NOCOUNT ON select * into CMI_Report from Case_Query_View where end_dt Is Null Or end_dt > @startdate and end_dt < @enddate --- ~This Query Replaces Name Veiw in the Report~ ---- select * into CMI_Report_Final_Data from Name_View ---- ~This is the defining query, This controls YTD and such! ---- SELECT nq.surname, nq.sw_ur, nq.MaxOfnext_rev_dt, cq.CTenddt, aq.LastOfadm_dt, aq.LastOfsep_dt, nq.end_dt, nq.clnt_id, nq.case_id, nq.HCPName, nq.hcp_id, cq.LastOfstart_dt, nq.MaxOfwellb_dt, (select MAX(dq.icd_desc) from Diagnosis_View dq where nq.clnt_id = dq.clnt_id) AS Diag

View Complete Post

More Related Resource Links

Syntax error (missing operator) in query expression

Good Day Gurus!

I have a Excel user application which has a user form (named 'Registo') that displays criteria and an image that has been entered in it's corresponding spreadsheet. This works the way it should.  There's also the ability to search the spreadsheet via a form (by clicking 'Pesquisar' button) this opens a search form. However, I having a bit of a problem with it. When I try to search for something it basically doesn't do anything at all. It just sits there. So I tried to debug it and I think I'm having a problem with either the JET db engine or somethign with teh query or maybe I don't have the correct reference.

I 'borrowed' this Excel application from another forum because it's exactly what I'm looking for! However, I suck at vb.

So I was hoping somebody could take a look at the code and see if I'm missing something?  I'm kinda' desparate to get this working because I'm been trying to figure it out for days and I'm running out of time.  Cry
Option Explicit

'constantes para auxiliar na verificação do código
Private Const Ascendente As Byte = 0

syntax problem passing parameter into Indexing Service Query

Hi everyone, I have the following query which works fine: select OriginalFileName from Document_Entries where EntryType like 'File%' and substring(entry,charindex('file_',entry),LEN(entry)) in (  SELECT filename FROM OPENQUERY(MySearchCat, 'SELECT Directory, FileName FROM SCOPE() WHERE    CONTAINS('' "green" '') ') )  It finds all documents in the document system which contain the word "green" using the index catalog.  My problem is that i need to include this query in a larger stored procedure which accepts a parameter for key words amongst others. I can't work out the syntax to get the @keywords parameter into query. The closest I've come is the following which runs but comes back with "incorrect syntax near keyword 'green'".  The @keywords parameter will contain any key words the user enters.   declare @keywords nvarchar(500) set @keywords='green'   Declare @query nvarchar(max) set @query = ' select OriginalFileName from Document_Entries where EntryType like ''File%'' and substring(entry,charindex(''file_'',entry),LEN(entry)) in (  SELECT filename FROM OPENQUERY(MySearchCat, ''SELECT Directory, FileName FROM SCOPE() WHERE    CONTAINS(''' + @keywords + ''') '')     )  )' exec(@query)   Any ideas? thanks Gus

Generic Query Designer displaying non standard syntax

I've just discovered a problem with the Generic Query Designer on my machine. When I do a simple join of two tabels it does not display in the SQL pane as standard syntax, so instead of SELECT a.1 from ainner join b on a.1=b.1It does SELECT a.1from a, bwhere a.1 = b.1I am doing this against an oracle 10g database, it will run the query, but I want the query designer to out put at standard SQLI am presuming that it is a setting in SSBIDS, but I don't know why it is doing this. Any suggestions?

Nested Full Text Query and SQL syntax



Quick question, is it possible to use the SQL TOP syntax in a Full Search Query something like

Select Top 1 title from SCOPE() where = 'All Sites' AND Productid= '1234556'


Can you use nesteed select statments ?

Select title from SCOPE() where = 'All Sites' AND Productid=  (select productid from scope() where scope = 'all sites' AND product = 'example')


Dave Roberts


Help Identifying What Wrong W/ Query Syntax - sp_send_dbmail



I know that I have probably done more than a few incorrect things in this statement but it works when I run it in the studio so I am not sure why it will not work when trying to use it from within sp_send_dbmail. I am pretty much new and learning as I go but this one has me lost.

My Error:

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

Here is what I am trying to run from Studio to validate that the syntax is correct before attempting to set it as a scheduled task.

DECLARE @like1 varchar(100);
SET @like1 = '%-LOST-%'; 
DECLARE @like2 varchar(100);
SET @like2 = 'LOST%-'; 
SET @sql = (SELECT ProfileName, LoginUser, ProfileDate, Filename, Product, Version, StartUp, Inuse, ServiceStatus, ServiceStartType, LastUsedTime, Directory
	  FROM computers c left outer join software s on c.id=s.id and filename='Flash10e.ocx' 
	  WHERE ProfileDate > GetDate()-1 
	  and (ProfileName not like @like1 and ProfileName not like @like2)
	  and version <> '10,1,82,76'
	  SELECT ProfileName, LoginUser, ProfileDate, Filename, Product, Version, StartUp, Inuse, ServiceStatus, ServiceStartType, LastUsedTime, Directory
	  FROM computers c left outer join software s on c.id=s.id and filename='Flash10i.ocx' 
	  WHERE ProfileDate > GetDate()-1

SQL Query within a form fails with "parser error" - syntax not correct?


Hello, I've created an Expression Web form with a SQL datasource which is doing a query/select statement.

Somehow it appears that I'm making a syntax error. When I divide the query in two and execute them separate, it works fine.

I need to filter for an EventType, Region and Today's date + a custom interval (like 7 day's for a week)

The parameters come from a search form where the user can select these values via a dropdown list.

The two separate (and working) queries within my form are:


Query nr.1 :

"Select * from Events WHERE  (([EventType] LIKE '%' + @EventType + '%') AND ([Region] LIKE '%' + @Region + '%'))">


<asp:formparameter DefaultValue="%" FormField="EventType" />

<asp:formparameter DefaultValue="%" FormField="Region" />


Query nr.2 :






SQL Query Syntax in Enterprise Search


Here is the sql query for FullTextSqlQuery:

SELECT url,DatePublished FROM portal..scope() WHERE ( ("SCOPE" ='All Sites')) AND url like '%url.com%' and artefacttype='aaa'


 the portal..scope() means? is there any other scope?

what is the url and artefacttype means, are those a customer column or something?


Also I want a tutorial document for MOSS 2007 search.

Including KeywordQuery, Query in a List View(SPQuery), CAML.


Thanks a lot!

error with sql query syntax


I run following query:

Grant view database state to domain\username

and get error message

Msg 102, level 15, state 1,Line 1

Incorrect syntax near '\'


How to fix it?

MS SQL Server: Search All Tables, Columns & Rows For Data or Keyword Query

If you need to search your entire database for specific data, this query will come in handy.

So when a client needs a custom report or some sort of custom development using Great Plains, most of the time I will have to track down the data in the system by running this query and find the table(s) it is in.

How to Encrypt Query String Parameters in ASP.NET

Encrypt Query String Parameters in ASP.NET.u can send secure data one page another page u can also use query string to encrypt

Content Query Web Part missing in SharePoint 2010

If you don't see content query web part listed in the web parts list, this is because you have not enabled "Search Server Web Parts" feature in site collection features. Enable this feature and content query web part will show in the list of web parts.

sql query that don't run



I'm going crazy... i've got a piece of code that don't update the database... Could somebody tel me why it doesn't run??

Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Dim cmdstring As String = "Update Corsi Set [Contenuto]='" & TxtText.Content & "' Where [ID]='" & Request.QueryString("Id").Replace("'", "") & "'"
        conn = New SqlConnection(SqlAnni.ConnectionString)
        cmd = New SqlCommand(cmdstring, conn)

Need help with a linq to sql query


I want to display some stats in a listview contril.  The table contains a record for every impression and for every click, and every record has a datetime field for the time and date of the impression of click.  I want to be able to display how many impressions and clicks there were in a given day and hour, something like below:

Date              Time                              Impressions    Clicks
8/20/2010                                               450              14            
                     Midnight -1:00am               150               5

Need Syntax To Make Results of LINQ Union Return Non-Generic Type



I have the below SQL which works just fine:

SELECT     Message, CreateDate, AccountId, AlertTypeId
FROM       dbo.Alerts
SELECT     TOP (100) PERCENT Status, CreateDate, AccountId,
                          (SELECT     10 AS Expr1) AS AlertTypeId
FROM         dbo.StatusUpdates
WHERE AccountId = PassedInParameter

I have been going about trying to convert the above into a LINQ method and am having problems with return types.
As the above SQL illustrates, I am querying two distinct LINQ tables - Alerts and StatusUpdates -
and then attempting to perform a Union on them. In order to do the union in LINQ, I have to have agreeing types. So, I
am using "var" to make the results of "alerts" and "updates" generic before the union.  

public IList GetStatusUpdatesAsAlertsByAccountId<T>(Int32 accountId)
            using (WorkbookDataContext dc = _conn.GetCont

How to send an email with information in query string


First I will say I googled (Binged to make Bill happy) for this but could not find anything, perhaps I am not stating what I need correctly;

I have a website that a customer creates orders (for a printing company) and after the order, I would like to email the customer a link to view the status of their order;

I need to send the CustomerID in the link so on the returning page if a CustomerID is detected in the querystring, I "auto login" the client and open the "Dashboard" for the order page for that customer.

Can anyone point me in the right direction as to how to send the link and how to parse the querystring to get the values from the link;

Thank you if you can point me in the right direction.

MDX Query parameter from SSRS


I've a MDX Query that has where clause as shown below.
I'm designing report using SSRS 2008. How can i pass date as parameter ? I tried to setup @from and @to as parameter but not working ?
any ideas....

WHERE ( {[Date Central].[Calendar Date].[2010-04-01 00:00:00]:[Date Central].[Calendar Date].[2010-08-30 00:00:00]} )

need it to work as
WHERE ( {[Date Central].[Calendar Date].[@From]:[Date Central].[Calendar Date].[@To]} )



Get ServerReport selected Parameter value to use in vb query


I'm using ReportViewer in Asp.net 2.0 to view a SSRS report. I need the value of the selected parameter to use in a vb query. The parameters are populated on the server and its a single selection. Doing searches I've come across  ReportViewer1.ServerReport.GetParameters() but I can't figure out if I can use this to determine which value the user has selected in the parameter dropdownlist. Any help would be appreciated.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend