Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Wednesday, March 28, 2012

Need to calculate a weighted average using sql

Help!!! I'm in a time crunch and need to calculate a weighted average.
Example: 85% of players will win $10.00, 5% will win $100. I have a table
that is storing the counter information. I just drawing a blank!!!
Any help is appreciated!!!JMainus,
Can you provide some DDL, sample data and expected result?
AMB
"JMainus" wrote:

> Help!!! I'm in a time crunch and need to calculate a weighted average.
> Example: 85% of players will win $10.00, 5% will win $100. I have a tabl
e
> that is storing the counter information. I just drawing a blank!!!
> Any help is appreciated!!!|||Alejandro,
I have a table that is storing the amounts available; $10, $20, $50 and
also the number of available awards per amount, and the percentage field
stores the weighted average; ex. 85% can win $10.
Thanks for your help.
"Alejandro Mesa" wrote:
> JMainus,
> Can you provide some DDL, sample data and expected result?
>
> AMB
> "JMainus" wrote:
>|||Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. Sample data is also a good idea, along with clear
specifications. It is very hard to debug code when you do not let us
see it.

Friday, March 23, 2012

Need some with query

Hi, I need some help formulating a query. Below is an example records.
What I am trying to do is to come up with a query that will tell me which
record has a position_startdate that is less than position_enddate from the
record above.
ID EMP_ID POSITION POSITION_STARTDATE POSITION_ENDDATE
-- -- -- -- --
--
18 18 SALES 1/21/03
6/5/04
25 18 SALES MGR 6/5/04
12/28/04
31 18 DEPT SUP 10/18/04
8/8/05
45 18 STORE MGR 8/8/05
null
In this example, the query should pickup ID = 31 since 10/18/04 is less than
the previous postion_enddate which is 12/28/04.
Also, I am running this query with tons or employees.
I am currently working on this and thought that I might post it and get a
quick response back.
Thanks,
JB..Rick Shaw wrote:

> Below is an example
> records. What I am trying to do is to come up with a query that will
> tell me which record has a position_startdate that is less than
> position_enddate from the record above.
You should provide more information to get a better answer but I think
this should do it, assuming that when you say 'record above' you mean a
record with a lower ID.
Select T1.* from Table T1 where T1.Position_StartDate < (select top 1
T2.Position_EndDate from Table T2 where T2.ID < T1.ID order by T2.ID
Desc)
HTH,
Stijn Verrept.|||Stijn Verrept wrote:

> Rick Shaw wrote:
>
> You should provide more information to get a better answer but I think
> this should do it, assuming that when you say 'record above' you mean
> a record with a lower ID.
> Select T1.* from Table T1 where T1.Position_StartDate < (select top 1
> T2.Position_EndDate from Table T2 where T2.ID < T1.ID order by T2.ID
> Desc)
Maybe
Select T1.* from Table T1 where T1.Position_StartDate < (select top 1
T2.Position_EndDate from Table T2 where T2.ID < T1.ID and T1.Emp_ID =
T2.Emp_ID order by T2.ID
Desc)
is better, depends if you need to compare it with the same Emp_ID or not
Kind regards,
Stijn Verrept.|||Thanks Stijn. It worked great.
Thanks again for the hand.
Rick..
"Stijn Verrept" <stjin@.entrysoft.com> wrote in message
news:v7KdnRH9lLMwlRjenZ2dnUVZ8qudnZ2d@.sc
arlet.biz...
> Stijn Verrept wrote:
>
> Maybe
> Select T1.* from Table T1 where T1.Position_StartDate < (select top 1
> T2.Position_EndDate from Table T2 where T2.ID < T1.ID and T1.Emp_ID =
> T2.Emp_ID order by T2.ID
> Desc)
> is better, depends if you need to compare it with the same Emp_ID or not
> --
> Kind regards,
> Stijn Verrept.

Wednesday, March 21, 2012

Need some help in searching

Dear ASP.NET

How can I find records that contain a STRING from some (more than one) other fields ?

for example, I have:

Name_First = "aaa"
Name_Middle = "bbb"
Name_Last = "ccc"

Key_Words = "aaa,bbb,ccc"
(includes all values - comma separated)

How can I do the SELECT so that when I search for "bbb" on Key_Words I will get my record ?

Should I use "LIKE %aaa%" or something like this ?
(should I keep the comma separators ?)

Thanks in advance, Yovav.You can use like % for sure. Generally when I have searching functions where a user can enter one or more fields

I apppend each field in the SQL string as I build it. So for example mine may look something like the following:

DECLARE @.SQLWHERE varchar(1000)
SET @.SQLWHERE = ''

IF @.FirstName IS NOT NULL
SELECT @.SQLWHERE = ' WHERE FirstName ' + ' LIKE ''' + '%' + @.FirstName + '%'''

IF @.LastName IS NOT NULL
BEGIN
IF @.SQLWHERE = ''
SELECT @.SQLWHERE = @.SQLWHERE + ' WHERE P.LastName ' + ' LIKE ''' + '%' +
@.LastName + '%'''
ELSE
SELECT @.SQLWHERE = @.SQLWHERE + ' AND P.LastName ' + ' LIKE ''' + '%' + @.LastName + '%'''
END

And you can keep doing that type of logic for as many as you would like,

Another option is not to include any "%" at all and then indicate on your textboxes where users search that they can enter a * or % for like searches.

Just food for thought.|||I doing this search on 6 NTEXT fields...
so I thought maybe it will be faster if I do it on one field that has the content of the all 6...

what do U think ?

+
How should I write it ?
"SELECT * FROM X WHERE Key_Words LIKE %'" & SearchString & "'%" ?|||' SELECT * FROM X WHERE FirstName ' + ' LIKE ''' + '%' + @.FirstName + '%'''
.LastName ' + ' LIKE ''' + '%' + @.LastName + '%'''

ANd keep appending for each additional field until you have all six included.

If this is a stored procedure assign your string to variable and then at the end
call exec yourVarialbename

For example

EXEC (@.SQLStatement)

Monday, March 19, 2012

Need sample code for asp + sql server

Hello,
I am developing for internet.
I need a good example for ASP page, that use sql-server with some update
commands + transactions (use insert/update command + beginTrans/EndTrans,
please.
Thanks
Try a site like http://www.asp101.com/ or http://www.4guysfromrolla.com/
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Avi" <nobody@.nospam_please.com> wrote in message
news:u8BcHvD8EHA.1292@.TK2MSFTNGP10.phx.gbl...
> Hello,
> I am developing for internet.
> I need a good example for ASP page, that use sql-server with some update
> commands + transactions (use insert/update command + beginTrans/EndTrans,
> please.
> Thanks
>
|||Have a look at
http://www.mindsdoor.net/aSP/DBAccess.inc.html

Need sample code for asp + sql server

Hello,
I am developing for internet.
I need a good example for ASP page, that use sql-server with some update
commands + transactions (use insert/update command + beginTrans/EndTrans,
please.
Thanks
Try a site like http://www.asp101.com/ or http://www.4guysfromrolla.com/
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Avi" <nobody@.nospam_please.com> wrote in message
news:u8BcHvD8EHA.1292@.TK2MSFTNGP10.phx.gbl...
> Hello,
> I am developing for internet.
> I need a good example for ASP page, that use sql-server with some update
> commands + transactions (use insert/update command + beginTrans/EndTrans,
> please.
> Thanks
>
|||Have a look at
http://www.mindsdoor.net/aSP/DBAccess.inc.html

Need sample code for asp + sql server

Hello,
I am developing for internet.
I need a good example for ASP page, that use sql-server with some update
commands + transactions (use insert/update command + beginTrans/EndTrans,
please.
Thanks :)Try a site like http://www.asp101.com/ or http://www.4guysfromrolla.com/
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Avi" <nobody@.nospam_please.com> wrote in message
news:u8BcHvD8EHA.1292@.TK2MSFTNGP10.phx.gbl...
> Hello,
> I am developing for internet.
> I need a good example for ASP page, that use sql-server with some update
> commands + transactions (use insert/update command + beginTrans/EndTrans,
> please.
> Thanks :)
>|||Have a look at
http://www.mindsdoor.net/aSP/DBAccess.inc.html

Need sample code for asp + sql server

Hello,
I am developing for internet.
I need a good example for ASP page, that use sql-server with some update
commands + transactions (use insert/update command + beginTrans/EndTrans,
please.
Thanks Try a site like http://www.asp101.com/ or http://www.4guysfromrolla.com/
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Avi" <nobody@.nospam_please.com> wrote in message
news:u8BcHvD8EHA.1292@.TK2MSFTNGP10.phx.gbl...
> Hello,
> I am developing for internet.
> I need a good example for ASP page, that use sql-server with some update
> commands + transactions (use insert/update command + beginTrans/EndTrans,
> please.
> Thanks
>|||Have a look at
http://www.mindsdoor.net/aSP/DBAccess.inc.html