Showing posts with label suppose. Show all posts
Showing posts with label suppose. Show all posts

Monday, February 13, 2012

beginner.. :-)

Hello there

I am a very beginner..

I need to know if this is the write structure for doing this:

1. this func call for 4 other func: is it suppose to look like this?

2. with what i should replace the RETURNS int if its return date & int

thanks

ALTER FUNCTION [dbo].[StatisticsEx2_0Func]

(

@.Date_M_Y smalldatetime ,

@.FK nchar (20) ,

@.BizID int

)

RETURNS int

AS

BEGIN

DECLARE @.ResultVar int

set @.ResultVar = (SELECT

dbo.StatisticsEx_2_1_SingleMonthlySumFunc.A, dbo.Statistics_2_1_SingleAnnualAvgFunc.B, dbo.Statistics_2_1_AllGropsMonthlyTotalFunc.C, dbo.StatisticsEx_2_1_AllGroupsAnnualAvgFunc.D

FROM dbo.Statistics_2_1_AllGropsMonthlyTotalFunc, dbo.Statistics_2_1_SingleAnnualAvgFunc, dbo.StatisticsEx_2_1_AllGroupsAnnualAvgFunc, dbo.StatisticsEx_2_1_SingleMonthlySumFunc)

RETURN @.ResultVar

END

If you want to return more than one value then use Inline Table /Table Valued UDF.

If you use sql server 2005 then you can utilize the UDT (.NET Class) to return as Structure.

Create Function [dbo].[StatisticsEx2_0Func]()

Returns table

as

Return

(

Select 100 i, Cast('1/1/2007' as Datetime) d

)

go

Select * from [dbo].[StatisticsEx2_0Func]()

|||

amm..

the "mother" func suppose to get 3 parm – every child func use 2 param out of the 3

then let the table

so...?

Create Function [dbo].[StatisticsEx2_0Func]()

Returns table

as

Return

(

Select

@.Date_M_Y smalldatetime ,

@.BizID int ,

@.FK

)

go

Beginner question - sorry

Suppose I have a group of members and I want they to groups in to different categories. Each member has an ID and I would like each group to have an ID- I guess in programming it would typically done with a 2 dimensional array or something. How does SQL do this? Also each member may belong to more than one group. and also - I though of creating a new table for each group but then I am afraid of the maintenance of so many tables and the groups could quickly go into the thousands and ten thousands. And it really doesn't fit into my design plans also.

Any help or ideas would be appreciated.

Thanks,Hi,

There are a number of solutions to this problem, one would be to create a Groups table, a Users table and a UsersPerGroups table.

Users

UserID | UserName
--------
1 | echo88
2 | taylorza
3 | tmorton

Groups

GroupID | GroupName
--------
1 | Admin
2 | Power User
3 | User

Putting users in groups is as easy as populating the UsersPerGroups table, in this case
echo88 belongs to the Admin and Power User groups
taylorza belongs to the User group
tmorton belongs to no groups

UsersPerGroup

UserID | GroupID
-------
1 | 1
1 | 2
2 | 3

Hope this helps