HOST_NAME() Filter Issue

Feb 5, 2007

I am using dynamic filtering on host_name() for SQL 2005 SP1 merge publication. It had been working fine, but something has caused the configuration to stop working.

Setting up the publication and a test subscription via the GUI works fine. However, if I script out the publication and subscription and attempt to run the script (with suitable password), then I get the error

€śa value for the parameter @host_name was specified while publication does not use host_name() for dynamic filtering€?

I did some digging and was curious to find some differences in the information returned by sp_helpmergepublication and the content of dbo.sysmergepublications.

The sp_helpmergepublication output showed expected content after both GUI and script setup €“ with a value of HOST_NAME() for validate_subscriber_info.

The content of dbo.sysmergepublications was as expected after setup via the GUI €“ with a value of HOST_NAME() for dynamic_filters_function_list.

However, I noticed that if I performed setup using scripts the dynamic_filters_function_list value was null.

Further note that the subset_filter_clause value was correct for the filtered article with both GUI and script setup (<column name> = HOST_NAME())

After some experimentation, I found that if I executed sp_changemergearticle to set the subset_filter_clause again (after all the normal publication setup scripts had run) €“ then the dynamic_filters_function_list value in dbo.sysmergepublications became correct €“ and everything started working again.

This looks like a bug to me €“ and although the workaround above seems to work €“ it would be good to know if this is a known issue

If this is not a known issue, then I will attempt to put together a simpler repro than I currently have available.

aero1

View 6 Replies


ADVERTISEMENT

Host_name

Nov 1, 2005

Hi,I have a question regarding host_name() and IP addresses of clients. I'mrunning on a shared server - so access to xp_cmdshell is barred which is thestandard response to questions about getting the IP address of a client fromsql server. My issue is this:For security reasons every user of our database system logs into our customsecurity system all under the *same* sql-server user name (who only hasaccess to a discrete set of stored procedures). This can't be changed as weare limited to 3 database users. I store the host_name that the user log'sin from when he logs in - and then check the host_name of any further callsto sp's under this login context. I have however just discovered thathost_name() is set in the connection string - so the client can pass prettymuch whatever he wants to - so all an imposter would have to do is *fake*the client name of an existing user. Is there anyway of detecting the *real*client's host? Is there any way of forcing a client to be limited to justone client machine? Can I get hold of the IP address in a reliable way?ThanksNick

View 4 Replies View Related

Replication With Host_name

Apr 13, 2006

Hello,

   I am wanting to limit the amount of rows that are merged between the server and the wm device. Host_name() doesn't seem to be supported in sql mobile. I created a column called host and set the default value as host_name(). I get the table to replicate however when I try to insert into the table on the mobile side I get errors. Is there another option to filter like this or if I hard code a deviceID how can I add this to the filter rows options? Thanks.

John

 

Table script:

CREATE TABLE [dbo].[tstHost](

[peoplid] [numeric](18, 0) NOT NULL,

[image] [image] NULL,

[host] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_tstHost_host] DEFAULT (host_name()),

[rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL CONSTRAINT [MSmerge_df_rowguid_F9DD287E09FF4064813E154D2F0ACBC6] DEFAULT (newsequentialid()),

CONSTRAINT [PK_tstHost] PRIMARY KEY CLUSTERED

(

[peoplid] ASC

)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

 

Query on sql mobile side:

insert into tsthost (peopleid) values (2)

Error:
FAILED: insert into tsthost (peopleid) values (2)
Error: 0x80040e14 DB_E_ERRORSINCOMMAND
Native Error:  (25503)
Description: The column name is not valid. [,,,Node name (if any),Column name,]
Interface defining error: IID_ICommand
Param. 0: 0
Param. 1: 0
Param. 2: 0
Param. 3:
Param. 4: peopleid
Param. 5:

View 1 Replies View Related

How To Get HOST_NAME Insted Of User_name()

Jun 7, 2001

All developers use same login to access database (I know is it is not the best solution)

We need track when user insert value or edit value in specific table
It is done by triger and work fine with USER_ID() or user_name()

But all users (developers) use same login and USER_ID() and user_name()always the same.

Please help me how can get HOST_NAME of user who is trying to modify table and place it into triger insted of user_name()

Thanks a lot

View 2 Replies View Related

Using Host_name(): Crossing My Fingers...

Jul 20, 2005

I did this thing with host_name(). I'm hoping someone can tell me ifI'm gonna get into trouble with this scheme before it's too late...I have maybe 75 users.They all call on a table of appointments (many thousands) and I dumpthe ones being viewed into a temp table named TaskTEMP.I am using a custom function within a View to grab a bunch of rows inone table and slap them into a single column on the records returnedby the view.Here's where I'm concerned-When I insert the records into the TempTable I insert the valueHOST_NAME() into every row of a column named myMachine.So the row looks like:TaskID aName myMachine1234 Jim Smith Dell1011235 Fran Jones Dell1011235 Mary Cat Dell101When I run the view, I get:TaskID myNames1234 Jim Smith1235 Fran Jones, Mary CatWhat I'm concerned about is when user 2 is looking at the same recordat the same time and inserts the following into TaskTEMP:1234 Jim Smith CompaqXYZ1235 Fran Jones CompaqXYZ1235 Mary Cat CompaqXYZI use the HOST_NAME()filter in the example below to deal with this sothat both user one and user two get what they want instead of:TaskID myNames1234 Jim Smith, Jim Smith1235 Fran Jones, Mary Cat, Fran Jones, Mary CatIt works great in testing. The obvious problem is if two users havethe same machine name, but in this installation business rules preventthat.I hope someone can either validate this approach or improve or trashit before it gets too late with this project.thanks.lqThe view and function look looks like this:SELECT TaskID, dbo.fn_myNameGroup(TaskID) AS myNamesFROM dbo.TaskTEMPGROUP BY TaskIDIDThe function looks like this:CREATE function dbo.fn_myNameGroup(@TaskID as int) returnsnvarchar(500)asbegindeclare @ret_value nvarchar(500)SET @ret_value=''Select @ret_value=@ret_value + '; ' + aName FROM TaskTEMP whereTaskID=@TaskID AND myMachine=HOST_NAME()RETURN RIGHT(@ret_value,LEN(@ret_value)-2)end

View 3 Replies View Related

Problem With HOST_NAME Function With Linked View

Oct 30, 2005

I have an Access 2000 MDB file with a SQL 7 back end. I have a main tablewith 50,000 records; and I have a selections table with 50,000 records foreach machine that uses the database (about 25-50). This allows each user tohave their own set of selections.The selections table has three fields: ID (int), Sel (bit), MachName(varchar). ID and MachName comprise the primary key.I have a view that combines the main table and the entries for theselections table for the current machine (SQL below). The view works finewhen opened in EM and QA. And if I create a pass-through query from myAccess MDB file, the results are displayed fine.However, if I link the view to the Access MDB file, I get "#Deleted" inevery field of every record (which seems to indicate that the records werethere and then they were gone). However, if I hard-code the machine nameinto the same view instead of using HOST_NAME and then relink the view tothe MDB file, the linked view opens fine. Only when I use HOST_NAME as aparameter in the view is there a problem with it.Anyone have any idea what's going on here, or have heard of any issues withHOST_NAME and ODBC linked objects? SQL for the view is below.Thanks!NeilSELECT INVTRY.*, InvtrySelections.Sel, InvtrySelections.MachNameFROM dbo.INVTRY INNER JOINdbo.InvtrySelections ONdbo.INVTRY.ID = dbo.InvtrySelections.IDWHERE (dbo.InvtrySelections.MachName = HOST_NAME())

View 20 Replies View Related

Problem With PreComputed Partitions And Numeric Partition Key (HOST_NAME())

Nov 2, 2006

BOL says the following (headed with important):

"The HOST_NAME() function returns an nchar value, so you must use CONVERT if the column in the filter clause is of a numeric data type, as it is in the example above. For performance reasons, we recommended that you not apply functions to column names in parameterized row filter clauses, such as CONVERT(nchar,EmployeeID) = HOST_NAME(). Instead, we recommend using the approach shown in the example: EmployeeID = CONVERT(int,HOST_NAME()). This clause can be used for the @subset_filterclause parameter of sp_addmergearticle (Transact-SQL), but it typically cannot be used in the New Publication Wizard (the wizard executes the filter clause to validate it, which fails because the computer name cannot be converted to an int). If you use the New Publication Wizard, it is recommended to specify CONVERT(nchar,EmployeeID) = HOST_NAME() in the wizard and then use sp_changemergearticle (Transact-SQL) to change the clause to EmployeeID = CONVERT(int,HOST_NAME()) before creating a snapshot for the publication."

We have setup a publication with this scenario and by accident a nonconvertable HOST_NAME slipped in when someone tried to create a subscription in the database with the wrong parameters.

The consequence was not only that he failed to create the misconfigured subscription but all our several hundred subscriptions failed to synchronize from this point on.

It's weird that one single subscription causes all other subscriptions to fail (BUG??) but how to resolve this miserable situation?

First thing I tried was to delete the faulty partition via the Publication Wizard but all I got was an nasty error which was also related to the SQL Server trying to convert the partition string to integer.....

The next thing I tryed was setting PreComputed Partitions to false and re-initialize all subscriptions. Also this did not help. All the failed subscriptions continued to fail synching.

As a thing of last resort I changed the article filter to convert the partition key to nvarchar and then compare it to the HOST_NAME() value. Thank god this worked and the existing subscriptions started to synch successfully again.

So my question is:
How do you correctly recover in this situation?
As it really a wanted feature that one faulty partition causes all subscriptions to fail?
Shouldn't it be possible to delete the unwanted partition?

Thank you for your help!

regards, Stefan

View 8 Replies View Related

Automatic Select Filter (something Like Global Table Filter)

Apr 15, 2008

Hello,

Here is my problem:


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)?


Thanks in advance.

Best regards,
Beroetz

View 5 Replies View Related

And/or Filter Field Not Enabled In The Group Filter Tab

Jan 26, 2006

Howdy,

I have a table that has a group. In this group, I want to filter by 2 different expressions, concatenated with an OR. BUT I can't change the "And/Or" column value for the first entry because it is grayed out. The column will automatically change to an OR value if both my expression column fields are the same (which I don€™t want) but if I put any other value in to the expression field of the second row, the "And/Or" field of the first row automatically changes to an AND.

PLEASE! How do I get the And/Or field "ungrayed" so I can change it to what I want?

The 2 filters I and using check the UserID = to the user, and the other is checking a count to get the Top N 1. (So just showing the current user and the top producer)

View 14 Replies View Related

Filter Help

Feb 3, 2007

Hello I am working in an advertising company and I have to find all records who have advertised 7 days back but if one person has advertised more than once means for different products, his name should come only once. How can I filter this. I am totally new to this language I can write simple query but don’t know how to filter it.
Name IndividualID Product Date
A 1 x 2007-01-27.23.59.59.777
A 1 y 2007-01-28.00.00.00.000

b 2 xx 2007-01-28.00.00.00.000

A 1 z 2007-01-28.00.00.00.000

b 2 yy 2007-01-28.00.00.00.000

A 1 p 2007-01-28.00.00.00.000

c 3 m 2007-01-28.00.00.00.000

d 1 n 2007-01-28.00.00.00.000

A 1 s 2007-01-28.00.00.00.000

View 1 Replies View Related

Filter On ' In Name

May 17, 2007

Hi,
I have a supllier named K O'Neill and i want to filter on his name in my supplier table . Is this possible ?

When I try Vend Name = 'K O%Neill' it does not work.

Can anyone help?


Thanks.

View 6 Replies View Related

Filter

Aug 21, 2006

I need a query that returns every n record from the database and the last record.
For every n-th is easy, but I need a
WHERE Index % n = 0
but I need a last one too.
Any Help.

View 3 Replies View Related

Filter &&amp; *

May 24, 2007

Hi I am wandering if it is possible to achieve the following:

I am using Reporting Services and Reporting services I got a report with a text parameter.
I would like the user to introduce AA and find the product AA and when he introduces AA* it finds AA, AAD, AAC...

I am doing the following:

Filter([DIM Product].[Product].ALLMEMBERS,
,IIF(INSTR(@Product, "*") > 0
,[DIM Product].[Product].currentmember.name = Replace(@Product, "%", "")
,INSTR([DIM Product].[Product].currentmember.name, @Product)
)
)

The problem ist that the function Replace does not work!

Does someone know how to do it?

View 1 Replies View Related

Using IN As Filter

May 22, 2007

What is the syntax for using IN as a filter? in SQL it would be IN( 'A', 'B', 'C') but this does not work in Reporting services.

View 4 Replies View Related

Formatting A Filter

Jun 9, 2008

In a SQLDataSource, the following line throws an error as an undefined function. FilterExpression='left$(lname,1) = "D"'
 Isn't this a standard VB function and why does it produce an error. How do I fix?
Thanks

View 2 Replies View Related

How To Filter Sqldatasource

Jun 8, 2006

Hi,
I am new in framework 2 and I can't find a way to filter the sqldatasource.
I have an sqldatasource control that retrive data from data base-"Select * from myTable"
I set the fiterExpression property-sqlDataSource1.FilterExpression="ID='" + strID + "' " ;
I don't know how to continue from here.If  I bound the  sqlDataSource1 to a control like gridView it works good and I see the filter oparation. but I want to get the result set  in the code and loop threw it like I did with ver 1.1 with sqldataReader:
While sqlDatareader1.Read {  myCode ... }
How can I do it with sqlDataSource ?
Thanks,
David
 
 
 

View 4 Replies View Related

JOIN Filter

Aug 24, 1999

I have two tables A and B. I want to insert data into tables C and D based on join between A and B (A.column = B.column). What is the best way to accomplish this type of task?

IE-------> If column = xyz then insert into table C
IF column = abc then insert into table D
ELSE do_not_insert

Please help.
Regards

Ziggy

View 1 Replies View Related

Profiler Filter

Sep 15, 2004

I have been running traces in SQL Profiler and have not been able to get the filtering to work correctly. I am interested in capturing only statements that use CPU and have setup the filter for CPU > 0. It still returns all of the rows that have Null. Is there any way of filtering out the rows that have nunll for CPU?

Thanks,
Ken Nicholson

View 2 Replies View Related

How Do I Add A Filter To This Query?

May 3, 2006

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

(

[Assigned To].[Person].CurrentMember,

[Work Item].[System_Id].CurrentMember,


[Date].[Year Week Date].[Date].&[2006-04-23T00:00:00],

[Measures].[Microsoft_VSTS_Scheduling_CompletedWork]

)

MEMBER [Measures].[Completed Work by WI on dt2] AS

(

[Assigned To].[Person].CurrentMember,

[Work Item].[System_Id].CurrentMember,

[Date].[Year Week Date].[Date].&[2006-04-29T00:00:00],

[Measures].[Microsoft_VSTS_Scheduling_CompletedWork]

)

MEMBER [Measures].[Completed Work] AS

[Measures].[Completed Work by WI on dt2] - [Measures].[Completed Work by WI on dt1]

SELECT
NON empty
{
[Measures].[Completed Work]

}

ON COLUMNS,

NON EMPTY

{
([Assigned To].[Person].[Person],[Work Item].[System_Id].[System_Id],[Work Item].[System_Title].[System_Title])


}

ON ROWS

FROM

[Team System]

----------End Statement---------------------------------------------------

View 1 Replies View Related

Filter Date

Jun 9, 2004

I got a field called Date#, datatype = datetime, default value = getdate().

So after i insert a record, the Date# will auto record the system date and the time. And my MS SQL Server show: 6/9/2004 12:24:35 PM

However i am not able to filter my record by date. The statement i tried are:

SELECT * from mytable WHERE Date# = '6/9/2004 12:24:35 PM'

SELECT * from mytable WHERE Date# = "6/9/2004 12:24:35 PM"

SELECT * from mytable WHERE Date# = 6/9/2004 12:24:35 PM

SELECT * from mytable WHERE Date# = '6/9/2004'

Pls help me,
Thanks a million

View 13 Replies View Related

Filter A Measure With MDX

Dec 27, 2005

HI all friends


I have a Fact table like this



DIMENSSIONSMEASURES
------------------------------
idempidprodcutsalessalesws




I just want make the next query with MDX


SELECT sales
FROM myFactTable
WHERE salesws > 0


Note that salesws is a measure not a dimmension


How it would be in MDX? I need a lot of help


Regards!

View 4 Replies View Related

Time Filter

Feb 6, 2006

Hi,
I need to filter my table to return data between 18:30 and 7:00

I am not sure how to do the half hour and span over midnight.

I think this might work for 18:00 and 7:00.

SELECT *
FROM MyTable
WHERE datePart(hour, Timestamp) Between 18 AND 24 Or datePart(hour, Timestamp) Between 00 AND 7

I would appreciate any help!

Thanks

View 5 Replies View Related

Problem With Like Filter.

Mar 15, 2008

I have a table with a varchar in it.

Inside the var char it contains data like:

Variable.[32] + Variable.[432] * (Variable.[333] / Const.[21])

What I am trying to do is search for all records that are using variable 333

I was trying:

SELECT * FROM my_table WHERE data_field LIKE '%Variable.[333]%'

However, that returning nothing.

I am going to guess that the [ ] need to be escape or something, but I don't know if thats really the issue.

Doing:

SELECT * FROM my_table WHERE data_field LIKE '%Variable%'

Works.

Thanks in advance,
Rich

View 2 Replies View Related

Where Clause Filter

Apr 14, 2008

I have an sql script that has 2 main blocks of Where filter which I'd call as Filter1 and Filter2 as follows:

Select
DisplayColumns...
From
InterestingTables
Where
(Filter1) --W1
AND --W2
NOT --W3
(Filter2) --W4

Note that Filter1 and Filter2 are composite filters (inner filters nested; it shouldn't matter as long as I have the outer parenthesis as above, right?).
Now, say SetF1ExF2 is the result set of the sql script above.
Additionally, let's say I obtain the result set SetF1 by having W2 to W4 commented out and SetF1AndF2 comes from commenting out W3.
Shouldn't the following hold: SetF1AndF2 = SetF1 - SetF1ExF2
I am having a discrepancy between the values with SetF1AndF2 < SetF1 - SetF1ExF2.

TIA.

View 1 Replies View Related

FILTER For MDX Query

Feb 17, 2012

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]

MDX is definitely not my strong point.

View 4 Replies View Related

Having Filter Problem

Apr 3, 2008

Hi ,
account_desc_out,Analysis_Desc_out,Sub_Analysis_Desc_out,debit_out,
credit_out,sub_Analysis_Code_out,Analysis_Code_out
-----------------------------------------------

11066-0001-01 GEN 6633 0.00000000 160.000000006633GEN

11066-0001-01 GEN 6633 160.00000000 0.000000006633GEN



When i run the below query the o/p is comming as above:actually no record should come bcz debit amt and credit amt should knock off .can anyone correct the below query:

select
account_code_desc as'Account_Desc_out',
analysis_code_Desc as'Analysis_Desc_out',
subanalysis_code_desc as 'Sub_Analysis_Desc_out',
case when drcr_flag='dr' then sum(isnull(base_amount,0)) else 0.00 end as 'debit_out',
case when drcr_flag='cr' then sum(isnull(base_amount,0)) else 0.00 end as 'credit_out',
subanalysis_code as 'sub_Analysis_Code_out',
analysis_code as 'Analysis_Code_out'
from Analysis_stg_tb as stg with (NOLOCK)
where subanalysis_code_desc='6633-Goverdhan S'
group by subanalysis_code,analysis_code,
account_code_desc,analysis_code_desc,subanalysis_code_desc,drcr_flag
having sum(case when drcr_flag='cr' then isnull(base_amount,0) else 0.00 end) -
sum(case when drcr_flag='dr' then isnull(base_amount,0) else 0.00 end)<>0
order by Account_Desc_out,Analysis_Desc_out,Sub_Analysis_Desc_out

View 1 Replies View Related

Where Filter Condition

Apr 18, 2008

Is there a difference if I use filter in the join instead in where clause:

1)

select s.*
from students s
join courses c
on s.ssn = c.ssn
and c.type = 'fresher'

2)
select s.*
from students s
join courses c
on s.ssn = c.ssn
where c.type = 'fresher'

Thanks...

View 5 Replies View Related

SQl Profiler Filter

Apr 21, 2008

Hi every one,
I want to filter application name in sql profiler, so I write SQL% (for every one who connects by sql qery analyzer) in "application name" filter box but it doesn't work correctly,and shows all applications. Why it works incorrect?
Thank You
Kini

View 1 Replies View Related

Year Filter

Jun 16, 2008

Ok I am experimenting with the data in this database and trying to determine the best way to write this query. I need to find patients that visited in 2005 or 2006 but have not come back since. At first I was doing it looking at patients that have only came in one time ever and that being in 2005 and 2006 but I think I may be missing some patients. I want to narrow it to patients that came in during 2005 and 2006 but have not come back since but I think I am just getting an unduplicated list of patients that visited during those years. Am I on track to do this with the query I have written and if so any ideas?


With PersonMIA (person_id,person_nbr,first_name,last_name,date_of_birth) as
(
select distinct person_id,person_nbr,first_name,last_name,date_of_birth

from
(select count(*) as countenc,a.person_id,a.person_nbr,
a.first_name,a.last_name,
a.date_of_birth
from person a
join patient_encounter b on a.person_id = b.person_id
where year(b.create_timestamp) IN (2005,2006)
group by a.person_id,a.person_nbr,a.first_name,a.last_name,a.date_of_birth)tmp
/*where tmp.countenc <=1*/
)
select description,mstr_list_item_desc, count(*)
from
(
select distinct c.description,tmp.person_id,tmp.person_nbr,tmp.first_name,
tmp.last_name,tmp.date_of_birth,d.payer_name,year(b.create_timestamp)as YOS,f.mstr_list_item_desc
from PersonMIA tmp
join person a on a.person_id = tmp.person_id
join patient_encounter b on a.person_id = b.person_id
join provider_mstr c on b.rendering_provider_id = c.provider_id
cross apply(select top 1 payer_name,payer_id
from person_payer
where person_id = tmp.person_id
order by payer_id) d
join payer_mstr e on d.payer_id = e.payer_id
join mstr_lists f on e.financial_class = f.mstr_list_item_id
where c.description = 'Leon MD, Enrique' /*and
year(b.create_timestamp) IN (2005,2006)*/
group by c.description,tmp.person_id,tmp.person_nbr,tmp.first_name,
tmp.last_name,tmp.date_of_birth,d.payer_name,b.create_timestamp,
f.mstr_list_item_dessc)tmp2
group by description,mstr_list_item_desc

Thanks in Advance!
Sherri

View 10 Replies View Related

Filter Between Two Dates

Aug 10, 2013

How to write sql query that will filter between two dates (user input in text box1 and text box2) in the below sql statement .

SELECT 'Table1' AS [Table], SUM(a) - SUM(b) AS Result FROM table1 UNION ALL SELECT 'Table2', SUM(a) - SUM(b) FROM table2 UNION ALL SELECT 'Table3', SUM(a) - SUM(b) FROM table3

View 2 Replies View Related

How To Filter On Maximum Value

Oct 23, 2013

how to filter on a maximum value ?

My query is this:

SELECT
ProdspecUID
,itemcode
,model
,revno

FROM prodspec

The revision numbers (revno) are unique per itemcode.I would like to get only the rows with the highest revision per itemcode, but I also need the prodspecUID with is the index key and therefore unique.I have tried MAX() and TOP 1's in sub queries, but up until now without any result.

View 3 Replies View Related

RDA Filter With Join?

Nov 20, 2007

I've setup RDA (Sql Server 2005) for my WM5 device and it works great to pull a simple table, even with a simple where clause.

I tried to join to tables to limit the number of records but I'm getting an error saying something about cannot track because of multitable query. So is it only possible to pull simple tables with RDA. If it is, is there a workaround?



Jesus saves. But Gretzky slaps in the rebound.

View 3 Replies View Related

Help With A Filter Query

Dec 20, 2007

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

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved