I am trying to write a query that will be able to select different segments of data based on spelling of the last name.
For example, in my database of name information, I need to select anyone whose last name starts with 'AAA' to 'EJJ'
then need to select anyone whose last name starts with 'EJK' to 'JAE' and so on...
I have tried using LIKE and some other methods with the > operator, but I can't get it to work. Does anyone have any suggestions or ideas on how to select data based on the alphanumeric characters this way?
Generally, on any screen, we design filter screen by allowing user to identify range or one value to search. But sometime in some screen, It will be more convenient for user if user can identify No matter how value to search.
For example On screen which have information of people in any province. So user would like to search it by identify no matter how value to search. There are check box of any province on filter part which enable users choose it.
Hence, if sometime user choose (by clicking on checkbox) 3 provinces : LA, Michigan, WachingtonDC to see description only 3 chosen province. and sometime user choose (by clicking on checkbox) 2 provinces : LA, Michigan to see description only 2 chosen provinces.
Please give me any idea for create Stored Procedure or any tecnique to complete my idea....
I need to return 1 ip address for each machine. I can easily achieve this with using group by and return max(ipaddress) however I would like to filter out specific range '192.168.%' but only want to do that if machine has more then 1 ip address. If the machine has only 1 ip address then it can return it even if its '192.168.%'
below is test table to show sample data
CREATE TABLE dbo.[testip]( [machineid] INT NULL, [ipaddress] [varchar](20) NULL ) GO INSERT INTO [dbo].[testip] ([machineid],[ipaddress]) VALUES (1,'155.119.1.22') INSERT INTO [dbo].[testip] ([machineid],[ipaddress]) VALUES (1,'192.168.1.5')
Hi friendsI have little problem here.I am creating data tables dynamically.I want to filter it using sql query.Suppose, I have four data tables with the same structure but records may be different.There are two fields ServiceMethod and Rates.Now I want to filter all tables and want to get match records with the ServiceMethod.Suppose,four records in First table,three records in other three tables,and only two records(Service method) are same in all tables.I want to that two records by filtering all tables and sum of rates and want to add matched records in new table and bind dropdownlist.Can any guide me how to filter more than one tables using sql query if data tables are created dynamically?Thanks in advance.
I am having a table which contain data in below form
id startvalue endvalue
1 12:00a 12:29a
2 12:30a 12:59a
3 1:00a 1:29a
4 1:00p 1:29p
5 2:00a 2:29a
Through SQL query I want to select the id column value for the row returned for the following query
select id from mytable where '1:24a' >= startvalue and '1:24a' <= endvalue
Idea is I will pass a literal value that lies between the startvalue (nvarchar column) and endvalue (nvarchar column) to fetch the id of the row returned, which should be 3 But when I run the query it returns me 2 rows for id 3 and 4.
I believe this is because I am trying to compare nvarchar columns with ">=" and "<=" operators.
Can anyone suggest how i can select the correct value or how to do this.
I'm an MDX newbie.. with some help I was able to create a query that returns accurate results. All I need to do now is filter for Completed Work value of greater than 0.
I have tried to use the filter wizard in VS2005, but I have never gotten the desired results.
Platform Info: SQL Server 2005 Standard VS2005
---------Start Statement---------------------------------------------------------- WITH
MEMBER [Measures].[Completed Work by WI on dt1] AS
I've got an MDX query I need to modify, but not quite sure how to proceed. I essentially know most of tye syntax, but am at a loss as to where the components of the syntax should appear in the query. Here is the original query:
Code:
WITH MEMBER [Employee].[FTE vs FL].[CF Total] AS AGGREGATE([Client Facing Disciplines]) MEMBER [Time].[Year - Half Year - Quarter - Month - Date].[Trailing 12 Months] AS AGGREGATE(LASTPERIODS(60, STRTOMEMBER(@SelectedMonthEx, CONSTRAINED))) MEMBER [Time].[Year - Half Year - Quarter - Month - Date].[YTD] AS AGGREGATE(YTD(STRTOMEMBER(@SelectedMonthEx, CONSTRAINED)))
[Code] ....
This is how I'm sure the two lines that say what should be excluded, I'm just not sure where they should go. I believe a FILTER statement is what I need, but not sure how to format it.
[Employee].[FTE vs FL].[Discipline].&[LOYALTY], [Employee].[FTE vs FL].[Discipline].[Department].&[OLSON PR Chicago]
Hello , I am Joining two tables and trying to filter the data based on some conditions. SELECT SERVICE_TICKET.SERVICE_TICKET_CODE,BuildingAddress.BuildingAddress, BuildingAddress.UserID,SERVICE_TICKET.PROBLEM_REPORTED, SERVICE_TICKET.CONTACT_PERSON, SERVICE_TICKET.STATUS FROM BuildingAddress INNER JOIN SERVICE_TICKET ON BuildingAddress.Customer_Site_Int_ID = SERVICE_TICKET.CUST_SITE_INT_ID WHERE (JoinTable.UserID = @parameter) AND (SERVICE_TICKET.SERVICE_TICKET_CODE LIKE 'HD' + '%') See in the query at the WHERE clause I am using JoinTable.UserID column actually I know that it is wrong . Could some one tell me how the query should be so that I can get the records from the join which matches the UserID column to a parameter. Hope that my question is clear. Thanks
So I have this query that is ignoring my date filter and for the life of me I can't figure out why. Was hoping some guru could explain it to me. Here goes:
This query ignores my date filter:
SELECT rcv.Name AS MachineName, r.JobId, j.Name AS JobName, r.CreateTime AS JCreateTime, rsv.Name AS JResultStatus, rpv.Path + rpv.Name AS ResourcePool, rcvv.ResourceConfigurationVal AS Dimension
FROM dbo.Result_View AS r INNER JOIN dbo.ResourceConfiguration_View AS rcv ON r.ResourceConfigurationId = rcv.Id INNER JOIN dbo.Job_View AS j ON r.JobId = j.Id INNER JOIN dbo.ResultStatus_View AS rsv ON r.ResultStatusId = rsv.Id INNER JOIN dbo.Resource_View AS rv ON rcv.ResourceId = rv.Id INNER JOIN dbo.ResourcePool_View AS rpv ON rv.ResourcePoolId = rpv.Id RIGHT JOIN dbo.ResourceConfigurationValue_View AS rcvv ON rv.LatestResourceConfigurationId = rcvv.ResourceConfigurationId LEFT JOIN dbo.Dimension_View AS d ON rcvv.DimensionId = d.Id
WHERE (r.CreateTime > DATEADD(DAY, -15, GETDATE())) AND (rcv.Name LIKE 'PNP%') AND (d.Id = 859) OR (d.Id = 860)
If I comment out the last two joins and associated select/filters, all of the sudden the date filter works again. From everything I have read, the joins are supposed to be processed BEFORE the filters are applied in the virtual table. My DB goes back a number of years and contains millions of records. W/O the date filter, the query takes a very, very long time to run.
I have an interface that allows the user to filter the data to be returned.
e.g. if the user selects @SeniorManager then the query should return all data related to this.
So if the user selects @SeniorManager and @Auditor then the query should return all data matching both @SeniorManager AND @Auditor.
FundID and ClientID are the ID's that link each table.
Am I correct in using UNION ALL below?? thanks.
Code Block SELECT SeniorMgr, null AS Auditor, null AS Legal FROM FundClient f INNER JOIN FundPortfolio p ON p.ClientID = f.ClientID INNER JOIN Staff s ON (s.ClientID = p.ClientID) AND (s.FundID = p.PortfolioID) AND (s.ClientID = f.ClientID) WHERE s.ClientID = @ClientID AND s.FundID = @FundID AND (@SeniorManager = null Or SeniorMgr = @SeniorManager) UNION ALL
SELECT null AS SeniorMgr, fa.Auditor, null AS Legal FROM FundClient f INNER JOIN FundPortfolio p ON p.ClientID = f.ClientID INNER JOIN (Auditor a INNER JOIN FundAuditor fa ON fa.AuditorID = a.Auditor) ON (a.ClientID = p.ClientID) AND (a.FundID = p.PortfolioID) AND (a.ClientID = f.ClientID) WHERE a.Auditor = @Auditor AND a.ClientID = @ClientID AND a.FundID = @FundID
UNION ALL
SELECT null AS SeniorMgr, null AS Auditor, fl.Legal FROM FundClient f INNER JOIN FundPortfolio p ON p.ClientID = f.ClientID INNER JOIN (Legal l INNER JOIN LegalCounsel fl ON fl.LegalID = l.Legal) ON (l.ClientID = p.ClientID) AND (l.FundID = p.PortfolioID) AND (l.ClientID = f.ClientID) WHERE l.LegalC = @Legal AND l.ClientID = @ClientID AND l.FundID = @FundID
Hello All, Can someone please help me with this problem. I have created additional profile properties for my users in the aspnet_profile table. One of the properties is named 'Division'. The division property is how I segregate users, for example, my company has multiple divisions and, the information that is displayed is dynamic according to which divison the user belongs to. Amost all of my stored proceedures are filtered by checking the value of Profile.Division of the logged in user. This system works great. The problem is, now I am working on user management and I need to create a Gridview that will display all of the users for a particular division but, I have no idea how to filter a query against the aspnet database to get the results I am looking for. Here is a small example:SELECT aspnet_Users.UserName, aspnet_Profile.PropertyNames, aspnet_Profile.PropertyValuesStringFROM aspnet_Profile INNER JOIN aspnet_Users ON aspnet_Profile.UserId = aspnet_Users.UserId******** Here is the part I need help with *********************WHERE PROFILE.DIVISION = KOr, can it even be done? Can you filter a query on the value of a profile property?Anyone have any ideas?Thanks in adavance for your help
We are working on an application which aggregates news articles from various sources. The problem is, when querying the database, is that there are a lot of double results because some of the sources get their news from the same press agency. To clarify things a bit here's a link to an example: http://84.244.146.27/Zoekresultaten.aspx?SearchQuery=Amsterdam As you can see, there are a lot of the same results. What we want is to filter out the double results irrespective of the source. In other words; when the query encounters the first result, display that and leave out the other same results. I've tried filtering them out by using DISTINCT on the 'news header' / results, but that does not seem to work. Any ideas on how to get this done? Any help is greatly appreciated!
Hi everybody have this query that list all the duplicate records meaning the occurence of pubinfid in more than one row. This gets me fine. Iwant thought to insert a where clause that further filters the result where pubid between 30 and 33. I tried placing it after the FROM CLAUSE BUT DOESN'T GIVE me what I want it still includes records other than the between clause. Also I tried placing it after the HAVING clause but it includes records which has only one count.. Where could I place the where clause or is ther an alternative for this.
SELECT a.pubinfid, a.pubid, a.pubcount FROM pubssubscribe AS a INNER JOIN (SELECT pubinfid FROM pubssubscribe GROUP BY pubinfid HAVING (COUNT(*) > 1)) AS b ON a.pubinfid = b.pubinfid
I need to find a 12-digit number in a column called "SequenceNumTxt", in a VERY long table.I can query the first n lines but need to add something like "WHERE [SequenceNumTxt]="123412341234".The above does not work, gives me a syntax error; what am I doing wrong?
I need to query the Employees table in the ABC database to find all employees who report to EmployeeID 5 (indicated by a value of 5 in the €˜ReportsTo€™ column) and who have the word €˜Sales€™ in their job title (i.e the Title column). In my database the Employees table is very large so you want to pre-filter the data before doing more complicated processing on it. How would I use the following statement to to pre-filter the data?
I use SQL Server 2005. I have approx. 50 tables in my database and 30 of them have a filed named "CompanyID". Example: create table A (ID int identity, NAME varchar(100), COMPANYID int)create table A (ID int identity, REF_ID int, FIELD1 varchar(100), FIELD2 varchar(100), COMPANYID int)
Also there are nearly 200 stored procedures that read data from these tables. Example: create procedure ABCasbegin /* some checks and expressions here ... */ select ... from A inner join B on (A.ID = B.REF_ID) where ... /* ... */end;
All my queries in the Stored procedure does not filter the tables by CompanyID, so they process the entire data.
However, now we have a requirement to separate the data for each company. That means that we have to put a filter by CompanyID to each of those 20 tables in each query where the tables appear.
Firstly, I put the CompanyID in the context so now its value is accessible through the context_info() function. Thus I do not need now to pass it as a parameter to the stored procedures.
However, I don't know what is the easiest and fastest way to filter the tables. Example:
I modified the above mentioned procedure in the following way: create procedure ABCasbegin /* some checks and expressions here ... */ -- gets the CompanyID from the context: DECLARE @CompanyID int; SELECT @CompanyID = CONVERT(float, CONVERT(varchar(128), context_info())) select ... from A inner join B on (A.ID = B.REF_ID) where ... and A.COMPANYID = @CompanyID and B.COMPANYID = @CompanyID /* ... */end;
Now I have the desired filter by CompanyID. However, modifying over 200 stored procedures is rather tedious work and I don't think that this is the best approach. Is there any functionality in SQL Server that can provide the possibility to put an automatic filter to the tables. For example: when I wrote "SELECT * FROM A", the actual statements to be executed would be "SELECT * FROM A WHERE CompanyID = CONVERT(float, CONVERT(varchar(128), context_info()))".
I was looking for something like "INSTEAD OF SELECT" triggers but I didn't manage to find any answer.
I would very grateful is someone suggests a solution for something like "global table filter" (that will help me make an easy refactoring)?
I have a simple ASP.NET application that allows the user to enter a Query in a TextArea and submit that to the database. Queries that contain Integer, String or other filters seem to work fine, but when the Query contains a Date or DateTime I have problems. Here is an example that works fine in Query analyzer but fails when executed in ASP.NET. "select top 10 * from Subscribers where StartDate < '09-03-2002'" In Query Analyzer no problem, in ASP.NET I get this error... Line 1: Incorrect syntax near ';' However if the Query uses '=' instead of a '<' or '' then it works without error "select top 10 * from Subscribers where StartDate ='09-03-2002'" Any help would be appreciated
how to add a date range filter to my database query. I want to be able to enter a date into ("E,6") and have VBA pull data >,= to that date range according to my "OPENED_DATE" dates. My code is pasted below:
I currently have a query in an access database that filters the records in a Sql Linked table for their user ID. So basically i use Environ("UserName") to filter for a field that contains their user name. I want to secure this and put it on the SQL Server so there is no way anyone can see any records other then the ones that are filtered for them. Does anyone know how to do this? I think it will be some SQL query.
Please refer to the below query. I want to filter inner join rows based on outer query column value (refer to bold text).
SELECT M.MouldId, SI.StockCode, MI.Cavity, MI.ShotCounter, CQ.SumOfCastedQty  as CastedQty, MI.CounterStartup FROM     MouldItem MI JOIN (SELECT JD.MouldId, JC.StockCode, SUM(JS.CastedQty) AS SumOfCastedQty FROM JobCasting AS JS INNER JOIN JobCreationDet AS JD ON JS.JobDetId = JD.Uniid INNER JOIN JobCreation AS JC ON JD.JobIdx = JC.Uniid
I have an SQL2005 db where I have some data I want to retrieve for a report. There are a couple of related tables holding some secondary info linked by foreign keys and one large table holding the bulk of the data. On my site I want to have a page where people can select filter options such as to display items that were entered before a date, after a date, between two dates, objects that are marked as complete in the table, etc.... Essentially various optional filters.
What I'm wondering is what's the best way to handle building the query to retrieve this data for the next page to display the report? I can think of a couple of ways but would essentially result in a lot of messy combining of strings to create the SQL query either in the C# code or in the stored procedure itself. I'm guessing, and hopping, there might be a cleaner method for this as it's a rather common thing I would think.
SELECT * FROM (SELECT [Patient Identifier], [Operator Index], Date, Time, ROW_NUMBER() OVER (PARTITION BY [Patient Identifier], Date ORDER BY [Patient Identifier], Date, Time) AS RowNum FROM Complete WHERE [Operator Index] <= 89) AS a WHERE RowNum <= 4 UNION SELECT * FROM (SELECT [Patient Identifier], [Operator Index], Date, Time, ROW_NUMBER() OVER (PARTITION BY [Patient Identifier], Date ORDER BY [Patient Identifier], Date, Time) AS RowNum FROM Complete WHERE [Operator Index] >= 90) AS a WHERE RowNum <= 2
This query returns values above 90 (I need 2 of them) or values between 80 and 89 (data is already filtered for only greater >=80) and I need 4 values above 80. I only need either 2 above 90 or 4 above 80, not both, and this query returns 2 above 90, but also the values between 80 and 89. If there are already 2 above 90, I do not want any values between 80 and 89. If there are 4 above 80, I do not need any additional values. If the are two above 80 and 1 above 90, I will take all of them (max I will ever take is 4).
SELECT [Patient Identifier], Date, [Operator Index], Time FROM (SELECT ISNULL(t9.[Patient Identifier], t8.[Patient Identifier]) AS [Patient Identifier], ISNULL(t9.Date, t8.Date) AS Date, ISNULL(t9.Rows, t8.Rows) AS Rows, c.[Operator Index], c.Time, ROW_NUMBER() OVER (PARTITION BY ISNULL(t9.[Patient Identifier], t8.[Patient Identifier]), ISNULL(t9.Date, t8.Date) ORDER BY c.Time) AS RowNum FROM (SELECT [Patient Identifier], Date, 2 AS [Rows] FROM [First Step] WHERE [Operator Index] >= 90 GROUP BY [Patient Identifier], Date HAVING COUNT(*) >= 2) AS t9 FULL JOIN (SELECT [Patient Identifier], Date, 4 AS [Rows] FROM [First Step] WHERE [Operator Index] >= 80 GROUP BY [Patient Identifier], Date HAVING COUNT(*) >= 4) AS t8 ON t8.[Patient Identifier] = t9.[Patient Identifier] AND t8.Date = t9.Date INNER JOIN Complete AS c ON c.[Patient Identifier] = ISNULL(t9.[Patient Identifier], t8.[Patient Identifier]) AND c.Date = ISNULL(t9.Date, t8.Date)) AS d WHERE d .RowNum <= d .[Rows]
Current Input Patient IDDATE Time Operator Index 5170000318OCT2006 11:48 91 5170000318OCT200611:50 100 5170000417OCT200611:41 89 5170000417OCT200611:50 93 5170000417OCT200611:52 91 5170000417OCT200612:00 93
Current Output
Patient IDDATE Time Operator Index 0517_0000318OCT200611:48 91 0517_0000318OCT200611:50 100 0517_0000417OCT200611:41 89 0517_0000417OCT200611:50 93
It should be Patient IDDATE Time Operator Index 5170000318OCT2006 11:48 91 5170000318OCT200611:50 100 5170000417OCT200611:50 93 5170000417OCT200611:52 91
The data is organized by patient id, date, time (ascending) For a given patient id, on a certain data, testing was performed. A value between 80 and 100 is acceptable data. I need either the first 2 tests with a score above 90 or the first 4 tests above 80. (The tests are further sorted by time because the testing is time dependant. On some occassions, there is just too much data. What is wrong with my current query?
Ultimately I want to be able to filter every field that is listed. However, for now I am just learning this stuff and would like to just filter the by the name in the "offense" field.
However, it is not binding the selection thus not filtering it out. Do you see any problems in my code?
I am using below code to fetch the data hit our webserver from different website or engine.
ex: If I pass the parameter Ref as google and the dates, will fetch the data (hits) from google.
I have created a table (PoList) to have names like google,amazon,aol upto 14 names.
My Question : How do I filter all (hits) the data which the name (Ref) is NOT in the PoList table.
Thanks in advance
CREATE PROCEDURE sp_Portals
@Ref as nvarchar(255), @SDate as Decimal(18,0), @EDate as Decimal(18,0)
AS
SELECT COUNT(b.Pcode) AS totclicks, case when b.Pcode = 'NPF' then b.Pcode + '-- No Products Found'
else a.prodmodel end as prodmodel, SUM(c.orderTot) AS [Sales Total], COUNT(c.cusID) AS NumSales,
b.Pcode as Code
FROM CusDetails c RIGHT OUTER JOIN View1 b LEFT OUTER JOIN Products a ON COALESCE (b.ProdID, 0) = a.ID ON c.sessID = b.SessID WHERE (b.Referer LIKE '%' + @Ref+ '%') AND (b.theDate >= @SDate) AND (b.theDate <= @EDate) GROUP BY b.Pcode, a.prodmodel ORDER BY totclicks DESC GO
I have a master database at headquarters which will be the publisher. I have 5 databases at client sites that have the same database schemas as the master, which will be the subscribers. Each table in the database contains a Customer_No column, which is set as a default to 1 at client 1, 2 at client 2, 3 at client 3, etc. The master database contains data for all customers.
How do I get Merge Replication to only replicate the data from the publisher based on the customer_no column in each table?
i want to filter the data on specified dates. (between dates).
SELECT a.UserID, b.Name, b.EmployeeNum,b.Department, MIN(a.TransactionTime) AS TransactionTime,a.TransactionTime as TR_Date, min(CONVERT(CHAR(20), TransactionTime, 113)) As TransactionDateTime FROM NitgenAccessManager.dbo.NGAC_AUTHLOG AS a INNER JOIN NitgenAccessManager.dbo.NGAC_USERINFO AS b ON a.UserID = b.ID WHERE (a.FunctionKey = ' ')
I need to create a report that shows daily events per hours, like this:
15.5. Example 00:00 8 01:00 9 02:00 34
Is this possible? The data should be filtered by the datetime. If the datetime is for example 15.5.2008 00:45, it goes to the first row of that example table I created.
I have a data column named Date_In with format of 20-May-13. How can I filter the data to select based on year only. I used
Select * From apps.xdmc_852@erpprod Where Year(Date_in) = 2014
This code is not working. I also need a way to automatically update to next week range. For example, last week I used where function like this
Where Date_in = to_date('01/12/2014','MM/DD/YYYY')
Is there a way it will automatically at the next 7 days to the code above when the date is available. This week I have to go back and changed the code in to this:
Where Date_in = to_date('01/19/2014','MM/DD/YYYY')