Showing posts with label write. Show all posts
Showing posts with label write. Show all posts

Thursday, March 22, 2012

Calling GetReportParameters within a report Code block?

I want to write a Code block routine that returns the parameter Prompts
and ValidValue that was selected from within the report. Can I access
the ReportParameters collection (not the parameters collection, but the
actual parameter definitions collection) from within a Code block?
Thanks,
--jasonDo you know that you can get both of the things you want without doing
anything special? Parameters!parametername.Value and
Parameters!parametername.Label Lots of people don't realize you can use
the .Label
--
Bruce Loehle-Conger
MVP SQL Server Reporting Services
<burt4684@.gmail.com> wrote in message
news:1104422606.388085.162050@.z14g2000cwz.googlegroups.com...
> I want to write a Code block routine that returns the parameter Prompts
> and ValidValue that was selected from within the report. Can I access
> the ReportParameters collection (not the parameters collection, but the
> actual parameter definitions collection) from within a Code block?
> Thanks,
> --jason
>|||Thanks, Bruce. I didn't know about the .Label property. That's good to
know. My only issue with .Value is some of my parameters are primary keys
and I need a good way to display the lookup values instead of the actual key
values. I was thinking I could iterate through the parameter.ValidValues
collection and display the ValidValue.Name that corresponds to the
parameter.Value that was selected. Do you know if this is possible?
Thanks,
--jason
"Bruce L-C [MVP]" wrote:
> Do you know that you can get both of the things you want without doing
> anything special? Parameters!parametername.Value and
> Parameters!parametername.Label Lots of people don't realize you can use
> the .Label
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> <burt4684@.gmail.com> wrote in message
> news:1104422606.388085.162050@.z14g2000cwz.googlegroups.com...
> > I want to write a Code block routine that returns the parameter Prompts
> > and ValidValue that was selected from within the report. Can I access
> > the ReportParameters collection (not the parameters collection, but the
> > actual parameter definitions collection) from within a Code block?
> > Thanks,
> >
> > --jason
> >
>
>|||Create another dataset that accepts the parameter as it's queryparameter.
You will end up with a single record (i.e. it has done your lookup), then
anywhere you need to use this value use this expression: =First(Fields!fieldname.value,"DatasetName")
Note that when you create a queryparameter RS adds a report parameter. If
you have the queryparameter with the same name as the reportparameter you
already have (must match case exactly since it is case sensitive) then your
query parameter and report parameter will already be mapped correctly.
This should do exactly what you need to do.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Jason Burton" <Jason Burton@.discussions.microsoft.com> wrote in message
news:7130300D-8A2E-40A3-9248-34E2EBDE40EB@.microsoft.com...
> Thanks, Bruce. I didn't know about the .Label property. That's good to
> know. My only issue with .Value is some of my parameters are primary keys
> and I need a good way to display the lookup values instead of the actual
key
> values. I was thinking I could iterate through the parameter.ValidValues
> collection and display the ValidValue.Name that corresponds to the
> parameter.Value that was selected. Do you know if this is possible?
> Thanks,
> --jason
> "Bruce L-C [MVP]" wrote:
> > Do you know that you can get both of the things you want without doing
> > anything special? Parameters!parametername.Value and
> > Parameters!parametername.Label Lots of people don't realize you can
use
> > the .Label
> >
> > --
> > Bruce Loehle-Conger
> > MVP SQL Server Reporting Services
> >
> > <burt4684@.gmail.com> wrote in message
> > news:1104422606.388085.162050@.z14g2000cwz.googlegroups.com...
> > > I want to write a Code block routine that returns the parameter
Prompts
> > > and ValidValue that was selected from within the report. Can I access
> > > the ReportParameters collection (not the parameters collection, but
the
> > > actual parameter definitions collection) from within a Code block?
> > > Thanks,
> > >
> > > --jason
> > >
> >
> >
> >|||As always, there's more than one way to skin a cat. Great idea. Thanks for
the help!
--jason
"Bruce L-C [MVP]" wrote:
> Create another dataset that accepts the parameter as it's queryparameter.
> You will end up with a single record (i.e. it has done your lookup), then
> anywhere you need to use this value use this expression: => First(Fields!fieldname.value,"DatasetName")
> Note that when you create a queryparameter RS adds a report parameter. If
> you have the queryparameter with the same name as the reportparameter you
> already have (must match case exactly since it is case sensitive) then your
> query parameter and report parameter will already be mapped correctly.
> This should do exactly what you need to do.
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "Jason Burton" <Jason Burton@.discussions.microsoft.com> wrote in message
> news:7130300D-8A2E-40A3-9248-34E2EBDE40EB@.microsoft.com...
> > Thanks, Bruce. I didn't know about the .Label property. That's good to
> > know. My only issue with .Value is some of my parameters are primary keys
> > and I need a good way to display the lookup values instead of the actual
> key
> > values. I was thinking I could iterate through the parameter.ValidValues
> > collection and display the ValidValue.Name that corresponds to the
> > parameter.Value that was selected. Do you know if this is possible?
> >
> > Thanks,
> >
> > --jason
> >
> > "Bruce L-C [MVP]" wrote:
> >
> > > Do you know that you can get both of the things you want without doing
> > > anything special? Parameters!parametername.Value and
> > > Parameters!parametername.Label Lots of people don't realize you can
> use
> > > the .Label
> > >
> > > --
> > > Bruce Loehle-Conger
> > > MVP SQL Server Reporting Services
> > >
> > > <burt4684@.gmail.com> wrote in message
> > > news:1104422606.388085.162050@.z14g2000cwz.googlegroups.com...
> > > > I want to write a Code block routine that returns the parameter
> Prompts
> > > > and ValidValue that was selected from within the report. Can I access
> > > > the ReportParameters collection (not the parameters collection, but
> the
> > > > actual parameter definitions collection) from within a Code block?
> > > > Thanks,
> > > >
> > > > --jason
> > > >
> > >
> > >
> > >
>
>

Calling Function From Stored Procdure ??

I'm a total novice with SQL, so please bare with me.
I'm trying to write a simple forum for my web site, i've done it before using Access but struggling to use the same idea with SQL. In acces i had one table for all the post and replies, i then had several querys that filtered off just the main topics and the number of replies for each thread. I did this by using multiple queries joined together, i've now found out that in SQL you cant call one strored procdure from another, so you have to use functions instead.

I have a stored procdure that filters off just the starter threads, but i want to also show how many replies ther has been for each topic and put then in date order of when they were posted.

this is my main stored procdure

CREATE PROCEDURE forum2 AS
SELECT forum.ForumID, forum.ID, forum.partID, forum.subject, forum.author, forum.message, forum.responder, forum.dtDate, forum.IpAddress, forum.PicID
FROM forum
WHERE forum.partID=0
ORDER BY dtDate DESC

this works ok and shows the main threads, but i also want to list the number of posts for each thread, i've got a function

CREATE FUNCTION dbo.CountofUsers()
RETURNS TABLE
AS RETURN
SELECT Count(*) AS CountOfID, forum.partID
FROM forum
WHERE forum.partID<>0
GROUP BY forum.partID

this should count the number of posts for each thread, but how do i combined the 2 together

i've messed about with adding "countofusers()" to the FROM clause in the procdure but i'm struggling!!! In acesses it something like "JOIN INNER..."
Please can anyone help!!In order to use table functions, assuming you are using SQL 2005 and not SQL 2000 in which case you are stuck and would have to either use cursors or else create an empty column which you update with the count afterwards, you need to join using either CROSS APPLY (like an inner join) or OUTER APPLY (like a left outer join).

E.g.

SELECT forum.ForumID, forum.ID, forum.partID, forum.subject, forum.author, forum.message, forum.responder, forum.dtDate, forum.IpAddress, forum.PicID,
CountofUsers.CountOfID
FROM forum
OUTER APPLY dbo.CountofUsers() CountofUsers
WHERE forum.partID=0
AND CountofUsers.partID = forum.partID
ORDER BY dtDate DESC

I would probably re-write the function to take a parameter for partID for optimal efficiency:

CREATE FUNCTION dbo.CountofUsers() (@.partID int)
RETURNS @.CountOfUsers TABLE (
CountOfID int,
partID int
)
AS
BEGIN
INSERT INTO @.CountOfUsers (
CountOfID
)
SELECT Count(*) AS CountOfID
FROM forum
WHERE forum.partID=(@.partID
RETURN
END

and then use the select like this:

SELECT forum.ForumID, forum.ID, forum.partID, forum.subject, forum.author, forum.message, forum.responder, forum.dtDate, forum.IpAddress, forum.PicID,
CountofUsers.CountOfID
FROM forum
OUTER APPLY dbo.CountofUsers(forum.partID) CountofUsers
WHERE forum.partID=0
ORDER BY dtDate DESC

Hope that helps.

Alternatively, I have found a way to be able to pass table results from one SQL stored procedure up to a caller via XML datatype output parameters. This simulates MARS behaviour with ADO.NET, allowing more than one resultset to be passed up as well. Check Books Online for more info.

Quote:

Originally Posted by Milkstr

I'm a total novice with SQL, so please bare with me.
I'm trying to write a simple forum for my web site, i've done it before using Access but struggling to use the same idea with SQL. In acces i had one table for all the post and replies, i then had several querys that filtered off just the main topics and the number of replies for each thread. I did this by using multiple queries joined together, i've now found out that in SQL you cant call one strored procdure from another, so you have to use functions instead.

I have a stored procdure that filters off just the starter threads, but i want to also show how many replies ther has been for each topic and put then in date order of when they were posted.

this is my main stored procdure

CREATE PROCEDURE forum2 AS
SELECT forum.ForumID, forum.ID, forum.partID, forum.subject, forum.author, forum.message, forum.responder, forum.dtDate, forum.IpAddress, forum.PicID
FROM forum
WHERE forum.partID=0
ORDER BY dtDate DESC

this works ok and shows the main threads, but i also want to list the number of posts for each thread, i've got a function

CREATE FUNCTION dbo.CountofUsers()
RETURNS TABLE
AS RETURN
SELECT Count(*) AS CountOfID, forum.partID
FROM forum
WHERE forum.partID<>0
GROUP BY forum.partID

this should count the number of posts for each thread, but how do i combined the 2 together

i've messed about with adding "countofusers()" to the FROM clause in the procdure but i'm struggling!!! In acesses it something like "JOIN INNER..."
Please can anyone help!!

|||Thanks for you explaination, very usefull, i am indeed using SQL 2000, i i guest i'm a little stuck. I thought what i was doing was quite straight forward but it apppears not to be!
I've tried using a sub query but didn't have much joy.
Can you suggest anything else that will get me going?? i'm only wrting a simple forum. (i dont have to use the table function, this was only a suggestion to me, if there is a better way for the fuction to work i can try it)|||Probably the easiest method is to create a temp table and insert the results of the SELECT statement from your function into it (either directly as a select or from the function or a stored procedure, if you want the piece of code to be reusable). Then perform a join to your previous result on partID to get the count value.

Saturday, February 25, 2012

Calendar Table

>> Hey Celko, didn't you once say you were going to write some stuff on
auxiliary tables? Haven't seen that yet... :) <<
I am banging away on the third edition of SQL FOR SMARTIES right now,
with a new and improved auxiliary tables chapter in it.
Minor design points:
1) do not use flags for each date type, but invent a single encoding
for holidays, workdays, etc. Leave room in the code for expansion, say
you have 100's for holidays, 110's for civil holdiays, 120's for
religious holidays, etc.
2) I prefer a BETWEEN predicate over comparisons (cal_date BETWEEN
order_complete_date AND order_ship_date), becuase it reads better for
someone maintaining the code.
But it also means I have to have constraints on the columns to adjust
the time part of the DATETIME columns to midnight today or a
microsecond before the next day.On 22 Jan 2005 11:48:16 -0800, --CELKO-- wrote:

>auxiliary tables? Haven't seen that yet... :) <<
>I am banging away on the third edition of SQL FOR SMARTIES right now,
>with a new and improved auxiliary tables chapter in it.
>Minor design points:
>1) do not use flags for each date type, but invent a single encoding
>for holidays, workdays, etc. Leave room in the code for expansion, say
>you have 100's for holidays, 110's for civil holdiays, 120's for
>religious holidays, etc.
Hi Joe,
This doesn't sound like a design I'd be too happy with.
First, the difference between civil holidays and religious holidays is
often not important at all. People shouldn't clutter their databases with
unimportant information.
Second, if this distinction is important, it is still a seperate attribute
(holiday_type). Trying to encode this distinct attribute into a numeric
range is a vioaltion of 1NF.
Third, using a meaningless, unverifiable numeric code for holidays is not
needed at all. At this point, I'm tempted to ask if you also believe that
God put a 17-letter hebrew number to everything in Creation. What's wrong
with calling St.Patrick's Day St. Patrick's Day, New Years Day New Years
Day and Christmas Christmas?

>2) I prefer a BETWEEN predicate over comparisons (cal_date BETWEEN
>order_complete_date AND order_ship_date), becuase it reads better for
>someone maintaining the code.
>But it also means I have to have constraints on the columns to adjust
>the time part of the DATETIME columns to midnight today or a
>microsecond before the next day.
But since the precision of date and time datatypes are not specified in
SQL-92 (at least not that I'm aware of), the microsecond before the next
day might get rounded up - and then your BETWEEN won't work. You'd have to
adjust the contents of the time table whenever you port your code.
Would you really throw away portability for "better reading" (which is
very subjective to boot)?
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||On 22 Jan 2005 14:01:55 -0800, --CELKO-- wrote:

> While
> in most cases, civil versus religious is not really needed unless you
> are being sued for discrimination, I can imagine wanting to know if a
> work-day called off for bad weather.
I can imagine running a db for a diverse organization, where some
departments get all holidays, others only get civil. Or where when an
employee takes off day X, you credit it to a holiday category if it is a
religious holiday even if it is not a standard company holiday (a variation
on your discrimination idea I guess). Anyway, I suppose the point could be
argued, but without business requirements there's not much point in
arguing.

Friday, February 24, 2012

Calculations at Run Time

Hi,
I am writting a report & want to calculate %age difference in last year &
current year's sales.
how do I write the expression or will have to write it in the SP I'm using
to run the report.
The problem is, I need to check the previous years sales value only if it is
greater than 0, then calculate the %age difference so it is something like
this
if prevYearSales > 0 then
currYearSales - prevYearSales / prevYearSales.
ThanksYou do it in an SP or as the following report expression
=IIF(Fields!prevYearSales.Value > 0,
Fields!currYearSales.Value - FIelds!prevYearSales.Value /
Fields!prevYearSales.Value,0)
It sets other values to 0 (the last expression)
--
Wayne Snyder MCDBA, SQL Server MVP
Mariner, Charlotte, NC
I support the Professional Association for SQL Server ( PASS) and it''s
community of SQL Professionals.
"Vishal" wrote:
> Hi,
> I am writting a report & want to calculate %age difference in last year &
> current year's sales.
> how do I write the expression or will have to write it in the SP I'm using
> to run the report.
> The problem is, I need to check the previous years sales value only if it is
> greater than 0, then calculate the %age difference so it is something like
> this
> if prevYearSales > 0 then
> currYearSales - prevYearSales / prevYearSales.
> Thanks
>
>

Sunday, February 19, 2012

calculation question

Hi,

how can write MDX in calculation for this case I highlighted in red?

product Sale contribution

-

a | 30.00 30/80 = 0.375

b | 50.00 50/80 =0.625

total | 80.00

-

[measures].[sale]/ sum ([measures].[sale] in current level ) ?

Thanks in advance.

Dear Friend,

try this and tell me if works:

Code Snippet

WITH
SET [InterestingProduts] AS
'{[Product].&[2],
[Product].&[1]}'

MEMBER [Product].[TotalOfInterestingProducts] AS
'SUM([InterestingProduts])'
MEMBER [MEASURES].[Percentage] AS
'[Measures].[Sales]/([Measures].[Sales],[Product].[TotalOfInterestingProducts])',

SOLVE_ORDER=5

SELECT {[Measures].[Sales],[MEASURES].[Percentage]} ON COLUMNS,
{[Product].members,[Product].[TotalOfInterestingProducts]} ON ROWS
FROM [YourCube]

Is more completed... but try if works!

regards!

|||

Hi PedroCGD,

Thanks for your code Smile

It works perfectly.

And I have another challenge that if I want to view percentage in each level (please see the example below) then how should I define for this scnario?

Currently, it only works in product a / b level. If I drill down and see the percentage then it calculates like this below:

i.g. product a-1 : 10/100 --> want to correct 10/30

product a-2: 20/ 100 > want to correct 20/30

percentage

product a

product a-1 10 10/30

product a-2 20 20/30

sub total 30 30/100

product b

product b-1 20 20/70

product b-2 50 50/70

sub total 70 70/100

Total 100

Here is the calculation script below:

CREATE MEMBER CURRENTCUBE.[Product].[Div-Quad Hierarchy].[Total] AS 'SUM([ALL])'; /* I may change this but not clear now */

CREATE MEMBER CURRENTCUBE.[MEASURES].[% Contrib Sls $]

AS

'[Measures].[Net Sale Dollars_Prod]/([Measures].[Net Sale Dollars_Prod], [product].[Div-Quad Hierarchy].[Total])',

SOLVE_ORDER=2,

FORMAT_STRING = "Percent",

VISIBLE = 1 ;

Please give me any comments.

Thanks in advance Smile

|||

Dear abc,

I'm happy you get it!! :-)

I will try to help you in your new requirement more late (few hours), ok? At the moment I'm very, very busy! :-(

Regards!!!

|||

Hi Pedro,

It seems you are busy Sad

If I run the mdx query,I can get a right result for each product level if I change this area that I highlighted in yellow.

But if I add this member in the calculation script then I don't know how to apply this for each particular product level.

FYI, I have product hierarchy (division > Q > Q name > ...) and we want to see the contribution percent in the total amount of the each product level not grand total of total products.

MEMBER [Product].[Div-Quad Hierarchy].[Total] AS

'SUM([Product].[Div-Quad Hierarchy].[division].&[interesting product name ])'

MEMBER [MEASURES].[Percentage] AS

'[Measures].[Net Purch Dollars_prod]/([Measures].[Net Purch Dollars_prod], [product].[Div-Quad Hierarchy].[Total])',

SOLVE_ORDER=2,

FORMAT_STRING="percent"

Please give me some comments.

Thanks in advance.

calculation question

Hi,

how can write MDX in calculation for this case I highlighted in red?

product Sale contribution

-

a | 30.00 30/80 = 0.375

b | 50.00 50/80 =0.625

total | 80.00

-

[measures].[sale]/ sum ([measures].[sale] in current level ) ?

Thanks in advance.

Dear Friend,

try this and tell me if works:

Code Snippet

WITH
SET [InterestingProduts] AS
'{[Product].&[2],
[Product].&[1]}'

MEMBER [Product].[TotalOfInterestingProducts] AS
'SUM([InterestingProduts])'
MEMBER [MEASURES].[Percentage] AS
'[Measures].[Sales]/([Measures].[Sales],[Product].[TotalOfInterestingProducts])',

SOLVE_ORDER=5

SELECT {[Measures].[Sales],[MEASURES].[Percentage]} ON COLUMNS,
{[Product].members,[Product].[TotalOfInterestingProducts]} ON ROWS
FROM [YourCube]

Is more completed... but try if works!

regards!

|||

Hi PedroCGD,

Thanks for your code Smile

It works perfectly.

And I have another challenge that if I want to view percentage in each level (please see the example below) then how should I define for this scnario?

Currently, it only works in product a / b level. If I drill down and see the percentage then it calculates like this below:

i.g. product a-1 : 10/100 --> want to correct 10/30

product a-2: 20/ 100 > want to correct 20/30

percentage

product a

product a-1 10 10/30

product a-2 20 20/30

sub total 30 30/100

product b

product b-1 20 20/70

product b-2 50 50/70

sub total 70 70/100

Total 100

Here is the calculation script below:

CREATE MEMBER CURRENTCUBE.[Product].[Div-Quad Hierarchy].[Total] AS 'SUM([ALL])'; /* I may change this but not clear now */

CREATE MEMBER CURRENTCUBE.[MEASURES].[% Contrib Sls $]

AS

'[Measures].[Net Sale Dollars_Prod]/([Measures].[Net Sale Dollars_Prod], [product].[Div-Quad Hierarchy].[Total])',

SOLVE_ORDER=2,

FORMAT_STRING = "Percent",

VISIBLE = 1 ;

Please give me any comments.

Thanks in advance Smile

|||

Dear abc,

I'm happy you get it!! :-)

I will try to help you in your new requirement more late (few hours), ok? At the moment I'm very, very busy! :-(

Regards!!!

|||

Hi Pedro,

It seems you are busy Sad

If I run the mdx query,I can get a right result for each product level if I change this area that I highlighted in yellow.

But if I add this member in the calculation script then I don't know how to apply this for each particular product level.

FYI, I have product hierarchy (division > Q > Q name > ...) and we want to see the contribution percent in the total amount of the each product level not grand total of total products.

MEMBER [Product].[Div-Quad Hierarchy].[Total] AS

'SUM([Product].[Div-Quad Hierarchy].[division].&[interesting product name ])'

MEMBER [MEASURES].[Percentage] AS

'[Measures].[Net Purch Dollars_prod]/([Measures].[Net Purch Dollars_prod], [product].[Div-Quad Hierarchy].[Total])',

SOLVE_ORDER=2,

FORMAT_STRING="percent"

Please give me some comments.

Thanks in advance.

Thursday, February 16, 2012

Calculation

I would like to write a query that would perform a calculation and but the
result in a new column.
Example
Value Value_Index Result (Value - Value_Index)
3.5 2.5 1
5 3 2
10 5 5UPDATE V
SET V.Result = (V.Value - V.Value_Index)
FROM tblValues V

Calculating totals

Hello. I am looking to write a query that will allow me to count all
pos_entry_code = 921 at all stores (card_acceptor_identification). Then hav
e
a total for each store. Is this possible? This is what I have so far. Do
I
need a group by and is there all way to list all the stores just not stores
with greater than 0. Thanks for any help.
Use WinPayment
GO
SELECT settlement_batch_number, card_acceptor_identification, id_number_1,
transaction_amount, id_code_1, host_response_string, count(*) count
FROM financial_message
where settlement_batch_number = '843'
and
pos_entry_mode = '921'
GROUP BY settlement_batch_number, card_acceptor_identification, id_number_1,
transaction_amount, id_code_1, host_response_string
HAVING COUNT(*) > 1
order by
card_acceptor_identificationThis is better if you do it in your client app / reporting tool. Take a look
to operator ROLLUP in BOL.
AMB
"tarheels4025" wrote:

> Hello. I am looking to write a query that will allow me to count all
> pos_entry_code = 921 at all stores (card_acceptor_identification). Then h
ave
> a total for each store. Is this possible? This is what I have so far. D
o I
> need a group by and is there all way to list all the stores just not store
s
> with greater than 0. Thanks for any help.
> Use WinPayment
> GO
> SELECT settlement_batch_number, card_acceptor_identification, id_number_1,
> transaction_amount, id_code_1, host_response_string, count(*) count
> FROM financial_message
> where settlement_batch_number = '843'
> and
> pos_entry_mode = '921'
> GROUP BY settlement_batch_number, card_acceptor_identification, id_number_
1,
> transaction_amount, id_code_1, host_response_string
> HAVING COUNT(*) > 1
> order by
> card_acceptor_identification|||So there is no way to easily sum numbers in SQL?
"Alejandro Mesa" wrote:
> This is better if you do it in your client app / reporting tool. Take a lo
ok
> to operator ROLLUP in BOL.
>
> AMB
> "tarheels4025" wrote:
>|||If you have a table with all the stores in it, use an outer join from it to
the financial_message Table...
SELECT S.card_acceptor_identification,
settlement_batch_number,
id_number_1, transaction_amount,
id_code_1, host_response_string,
count(*) count
FROM StoresTable S
Left Join financial_message M
On M.card_acceptor_identification =
S.card_acceptor_identification
Where settlement_batch_number = '843'
and pos_entry_mode = '921'
GROUP BY S.card_acceptor_identification,
settlement_batch_number,
id_number_1,transaction_amount,
id_code_1, host_response_string
HAVING COUNT(*) > 1
Order By card_acceptor_identification
"tarheels4025" wrote:

> Hello. I am looking to write a query that will allow me to count all
> pos_entry_code = 921 at all stores (card_acceptor_identification). Then h
ave
> a total for each store. Is this possible? This is what I have so far. D
o I
> need a group by and is there all way to list all the stores just not store
s
> with greater than 0. Thanks for any help.
> Use WinPayment
> GO
> SELECT settlement_batch_number, card_acceptor_identification, id_number_1,
> transaction_amount, id_code_1, host_response_string, count(*) count
> FROM financial_message
> where settlement_batch_number = '843'
> and
> pos_entry_mode = '921'
> GROUP BY settlement_batch_number, card_acceptor_identification, id_number_
1,
> transaction_amount, id_code_1, host_response_string
> HAVING COUNT(*) > 1
> order by
> card_acceptor_identification|||I am receiving an error that says Ambiguous column name
'Card_Acceptor_Identification'. What does that mean? Thanks.
"CBretana" wrote:
> If you have a table with all the stores in it, use an outer join from it t
o
> the financial_message Table...
> SELECT S.card_acceptor_identification,
> settlement_batch_number,
> id_number_1, transaction_amount,
> id_code_1, host_response_string,
> count(*) count
> FROM StoresTable S
> Left Join financial_message M
> On M.card_acceptor_identification =
> S.card_acceptor_identification
> Where settlement_batch_number = '843'
> and pos_entry_mode = '921'
> GROUP BY S.card_acceptor_identification,
> settlement_batch_number,
> id_number_1,transaction_amount,
> id_code_1, host_response_string
> HAVING COUNT(*) > 1
> Order By card_acceptor_identification
> "tarheels4025" wrote:
>|||That that Column name is in more than one of the tables referenced in your
query, so you have to "Qualify" it where you used it with a prefix, which
specifies which table you want it to come from... Thius is my bad, I missed
it. Notice the "S." in the first line? Well, I should have done the sam
e
thing where I used the column name in the Order By as well. That tells the
Query Processor to Order By The value of card_acceptor_identification in the
"S" Table (S is the alias assigned to the StoresTable by the syntax "Stores
As S" (Actually I left out the word "As" Since it's optional)
ANyway, below is the changed version:
Again, replace the "StoresTable" with whatever your table is actually named.
.
SELECT S.card_acceptor_identification,
settlement_batch_number,
id_number_1, transaction_amount,
id_code_1, host_response_string,
count(*) count
FROM StoresTable S
Left Join financial_message M
On M.card_acceptor_identification =
S.card_acceptor_identification
Where settlement_batch_number = '843'
and pos_entry_mode = '921'
GROUP BY S.card_acceptor_identification,
settlement_batch_number,
id_number_1,transaction_amount,
id_code_1, host_response_string
HAVING COUNT(*) > 1
Order By S.card_acceptor_identification
"tarheels4025" wrote:
> I am receiving an error that says Ambiguous column name
> 'Card_Acceptor_Identification'. What does that mean? Thanks.
> "CBretana" wrote:
>|||That worked thank. Is there a way to show every store and the totals from
each store. Maybe show every store from store table and then a column that
says count. Thanks
"CBretana" wrote:
> That that Column name is in more than one of the tables referenced in your
> query, so you have to "Qualify" it where you used it with a prefix, which
> specifies which table you want it to come from... Thius is my bad, I miss
ed
> it. Notice the "S." in the first line? Well, I should have done the s
ame
> thing where I used the column name in the Order By as well. That tells t
he
> Query Processor to Order By The value of card_acceptor_identification in t
he
> "S" Table (S is the alias assigned to the StoresTable by the syntax "Stor
es
> As S" (Actually I left out the word "As" Since it's optional)
> ANyway, below is the changed version:
> Again, replace the "StoresTable" with whatever your table is actually name
d...
> SELECT S.card_acceptor_identification,
> settlement_batch_number,
> id_number_1, transaction_amount,
> id_code_1, host_response_string,
> count(*) count
> FROM StoresTable S
> Left Join financial_message M
> On M.card_acceptor_identification =
> S.card_acceptor_identification
> Where settlement_batch_number = '843'
> and pos_entry_mode = '921'
> GROUP BY S.card_acceptor_identification,
> settlement_batch_number,
> id_number_1,transaction_amount,
> id_code_1, host_response_string
> HAVING COUNT(*) > 1
> Order By S.card_acceptor_identification
>
> "tarheels4025" wrote:
>|||tarheels4025,
I'm not sure what you are now asking...
The last query I posted, if i tworked SHOULD be showing every store, and a
column that says Count...
Could you be more specific?
"tarheels4025" wrote:
> That worked thank. Is there a way to show every store and the totals from
> each store. Maybe show every store from store table and then a column tha
t
> says count. Thanks
> "CBretana" wrote:
>|||Well it is only showing the stores that have more than one instance of a
pos_entry_code of 921. I would like all stores to be shown and show the
count of each store of instances of 921. The count will be a total for each
store. I hope that explains it. Thanks.
"CBretana" wrote:
> tarheels4025,
> I'm not sure what you are now asking...
> The last query I posted, if i tworked SHOULD be showing every store, and
a
> column that says Count...
> Could you be more specific?
> "tarheels4025" wrote:
>|||Might it have something to do with having count(*)>1?
thx
md
*** Sent via Developersdex http://www.examnotes.net ***

Sunday, February 12, 2012

Calculating Age...

Hello..
I am attempting to write a T-SQL script that will calculate a person's age
based on a date in the DOB field. The DOB field is a smalldatetime. I want
to return this calculated field in a result set. So for example, if the
date in the DOB field is 01/01/1900... I want the age to be returned as 105
(2005 - 1900). I am using SQL Server 2000
Any help would be appreciated...
Thanks,
Bretthttp://www.aspfaq.com/2233
This is my signature. It is a general reminder.
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
"Brett Davis" <bdavis123@.cox.net> wrote in message
news:OTREukdQFHA.2932@.TK2MSFTNGP09.phx.gbl...
> Hello..
> I am attempting to write a T-SQL script that will calculate a person's age
> based on a date in the DOB field. The DOB field is a smalldatetime. I
> want to return this calculated field in a result set. So for example, if
> the date in the DOB field is 01/01/1900... I want the age to be returned
> as 105 (2005 - 1900). I am using SQL Server 2000
> Any help would be appreciated...
> Thanks,
> Brett
>
>|||So say that this date is the birth date:
DROP FUNCTION TIMEMEMORIAL
GO
CREATE FUNCTION TIMEMEMORIAL
(
@.BIRTHDATE smalldatetime,
@.CURRENTDATE smalldatetime
)
RETURNS VARCHAR(200)
AS
BEGIN
DECLARE @.CURRENTYEAR CHAR(4)
DECLARE @.BIRTHYEAR CHAR(4)
DECLARE @.Result varchar(200)
SET @.BIRTHYEAR = CAST(YEAR(@.BIRTHDATE) as Char(4))
SET @.CURRENTYEAR = CAST(YEAR(@.CURRENTDATE) as Char(4))
Select @.result = CAST(datediff(yy,@.BIRTHDATE,@.CURRENTDATE
) AS varchar(10)) +
' (' + @.BIRTHYEAR + ' - ' + @.CURRENTYEAR + ')'
RETURN @.Result
END
Select dbo.TimeMemorial('20000101',getdate())
HTH, Jens Smeyer
http://www.sqlserver2005.de
--
"Brett Davis" <bdavis123@.cox.net> schrieb im Newsbeitrag
news:OTREukdQFHA.2932@.TK2MSFTNGP09.phx.gbl...
> Hello..
> I am attempting to write a T-SQL script that will calculate a person's age
> based on a date in the DOB field. The DOB field is a smalldatetime. I
> want to return this calculated field in a result set. So for example, if
> the date in the DOB field is 01/01/1900... I want the age to be returned
> as 105 (2005 - 1900). I am using SQL Server 2000
> Any help would be appreciated...
> Thanks,
> Brett
>
>|||See :
http://groups.google.ca/groups?selm...FTNGP09.phx.gbl
Anith|||I think this is easier;
checking for VALID data...
Making assumption that your want it from TODAY
select
case
when ISDATE(convert(char(15),[DATEFIELD])) = 0 then null
else
datediff(year, convert(datetime,([DATEFIELD])),getdate(
))
end
"Brett Davis" wrote:

> Hello..
> I am attempting to write a T-SQL script that will calculate a person's age
> based on a date in the DOB field. The DOB field is a smalldatetime. I wa
nt
> to return this calculated field in a result set. So for example, if the
> date in the DOB field is 01/01/1900... I want the age to be returned as 10
5
> (2005 - 1900). I am using SQL Server 2000
> Any help would be appreciated...
> Thanks,
> Brett
>
>
>|||On Fri, 15 Apr 2005 10:29:04 -0700, Jim Yurt wrote:

>I think this is easier;
>checking for VALID data...
>Making assumption that your want it from TODAY
>select
>case
>when ISDATE(convert(char(15),[DATEFIELD])) = 0 then null
>else
>datediff(year, convert(datetime,([DATEFIELD])),getdate(
))
>
>end
Hi Jim,
But that will return the number of year boundaries (dec 31 / Jan 1)
since the birth date, not the age!
SELECT DATEDIFF(year, '20041231', '20050101'),
DATEDIFF(year, '20040101', '20051231')
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Try This:
If @.DOB is datetime date of birth, and
@.CurDT is a dateTime with current date, then
Select Year(@.CurDT) - Year(@.DOB) -
Case When Month(@.CurDT) < Month(@.DOB) Then 1
When Month(@.CurDT) > Month(@.DOB) Then 0
When Day(@.CurDT) < Day(@.DOB) Then 1
Else 0 End
"Brett Davis" wrote:

> Hello..
> I am attempting to write a T-SQL script that will calculate a person's age
> based on a date in the DOB field. The DOB field is a smalldatetime. I wa
nt
> to return this calculated field in a result set. So for example, if the
> date in the DOB field is 01/01/1900... I want the age to be returned as 10
5
> (2005 - 1900). I am using SQL Server 2000
> Any help would be appreciated...
> Thanks,
> Brett
>
>
>

Calculating Age based on Document Date in months

Hi, I'm trying to write a formula that will calculate a patient's age based on the visit date and then converting it into months. Anyone know how to do that?
The variables would be:
{DOCUMENT.CLINICALDATE}
{PERSON.DATEOFBIRTH}The next will calculate age in years
({DOCUMENT.CLINICALDATE} - {PERSON.DATEOFBIRTH}) / 365

The next will calculate age in months
({DOCUMENT.CLINICALDATE} - {PERSON.DATEOFBIRTH}) / 365 * 12