Showing posts with label guys. Show all posts
Showing posts with label guys. Show all posts

Wednesday, March 28, 2012

How to make multiple-valued in one parameter in Query Builder?

Dear all,

I have a problem over here, hope to get some good advices from you guys.

I use Query Builder in VS2005 where you could see some tables on top, queries on the middle and resultset on the bottom windows.

I have a statement like below:

SELECT...WHERE Booking.BookingType IN (@.Type1, @.Type2, @.Type3, @.Type4, @.Type5)...

However, I found out that there are too many parameters, I wish to have only ONE parameters in the list of IN() operator. Is there any way to do it? Thanks!

I would suggest giving a look to Jens Suessmeyer's SPLIT function; the definition of this function can be found here:

http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=419984&SiteID=17

You ought to be able to code up your lists as comma separated strings and create a query that

looks something like this:

Code Snippet

SELECT...

from Booking

join split (@.yourParm, ',')

on Booking.BookingType = splitValue

Another alternative is to pass your argument as XML and use SQL Servers XML ability to interpret the XML argument.

Another question: Are you trying to make a parameter similar to a multi-value parameter that is available in Reporting Services? If the answer to that question is "YES" then you need to understand that feature is only available in Reporting Services and is not in general available to Transact SQL.

|||

If you are trying to reduce the number of parameters, just remove them from inside the paretheses.

In fact, if you are ONLY testing for a single parameter, use equals instead of IN (...) -it may be a bit more efficient.

|||

Actually, what I wish to have is putting a list of values in the @.Param programmatically in my code, thus, I wish to have one single @.Param instead of multiple @.Param(s) in SQL. I used Query Builder GUI to build my SQL query in VS2005, however, I couldn't find way to just put one @.Param and set multiple values in it.

For e.g.

SELECT * FROM Booking WHERE Type IN ( @.Param );

C# Code:

....DataTable1.GetData("Lab, Meeting, Course");

Is this possible to do this?

Thanks!

|||

There is no direct way to do something like

Code Snippet

SELECT * FROM Booking WHERE Type IN ( @.Param );

in which @.param contains data such as 'Lab, Meeting, Course'. Again, I would suggest using the SPLIT function to accomplish your objective.

Wednesday, March 21, 2012

How to maintain users permission and access level

Hi guys,

We have a scenario where there are about 50 tables in our database and we want to build an intranet web application for users to with the office to access those tables.

Users ability to access tables falls into diferent category:

Some users can NOT view some tables at allSome users can ONLY view some tables but not insert/update any fieldSome users can view and also insert/update some tables (in the same time they might not have view(select) permision on some other tables)

Now, what is the right way to implement this.

I say we have to have a Role, RolePermission, User, UserPermission inside our database to implement this (something which would look like the Roles and Users inside MSSQL) and we only have one user for our Database (MachineName/ASPUSER) to access the database and all the tables within

My colleague says NO, instead of creating all these tables and implement this, we add every user of our application as a Database user inside MSSQL in the Databse Users.

All the web application I have seen so far, DNN, CommunityServer, ... the have tables to implement all these and they don't add users inside the MSSQL.

Now which way is the way to go with, and what problem might we fall into if we use SQL users, is this possible at all. How can I convince him that we have to make and use our own tables to manage this.

Thanks for any help,
Mehdi

If you are using asp.net 2.0 you can use login controls and restrict the users to access particular forms.

Other way is to use Windows based authentication. As you are creating Intranet based application...every user will have windows ID. You can restrict the user to access the database.

To learn about Windows Based Authentication, visit the following link:

http://msdn2.microsoft.com/en-us/library/aa480475.aspx

To learb about login controls, watch the video tutorial for Membership and Roles

http://www.asp.net/learn/videos/default.aspx?tabid=63#howdoi

|||go to http://www.codeproject.com/csharp/cgsecurity3.aspit was presented a library for managing user-level credentials

How to Maintain TransLog (Detach/attached)

hi guys, we have a translog database (.LDF) of 60 GB which the contain database itself (.MDF) is only 500 MB. I have detached the translog and succeeded, but when i tried to attached the MDF file, there was an error message says "physical device error D:\\...". Please advice, what should we do towards the .LDF file (60 Gigs) - our objective is to delete/decrease the LDF file mentioned. Thanks in advance.Try this page:

http://www.support.microsoft.com/?id=272318

Basically you want to eliminate the data within the log then shrink the footprint of the file. Also, if you do not require transactional recovery you might consider using simple recovery mode which truncates the log upon checkpoint of the data.

HTH

How to loop through each row in table?

Hi guys,
Is there a trivial way for looping through each record in a table
that's equivalent to plsql's
for r1 in (select * from tablename) loop
v_name := r1.name;
...
end loop
?
I've tried the cursor approach but realised I'll need to define a
variable for each column inside the table. So am currently looking for
an alternative.
Thanks in advance.If you have to loop, then curosor is the only way.
--
"Opal" wrote:

> Hi guys,
> Is there a trivial way for looping through each record in a table
> that's equivalent to plsql's
> for r1 in (select * from tablename) loop
> v_name := r1.name;
> ...
> end loop
> ?
> I've tried the cursor approach but realised I'll need to define a
> variable for each column inside the table. So am currently looking for
> an alternative.
>
> Thanks in advance.
>|||Am 2 May 2006 21:23:29 -0700 schrieb Opal:

> Hi guys,
> Is there a trivial way for looping through each record in a table
> that's equivalent to plsql's
> for r1 in (select * from tablename) loop
> v_name := r1.name;
> ...
> end loop
> ?
> I've tried the cursor approach but realised I'll need to define a
> variable for each column inside the table. So am currently looking for
> an alternative.
>
> Thanks in advance.
If you have SQL2000 or above you can use TOP.
Here an example, let's say table has a unique field called id, which starts
with a value > 0:
select @.x = 0, @.y = max(id) from table
while @.x < @.y begin
select top 1 @.x = id, @.name = field1 from table where id > @.x order by id
.. do something with @.name ...
end
bye, Helmut|||Hi Opal,
You only need to declare variables for the columns you want, so if you are
only interested in [name] then just select that on the select statement in
the cursor...
declare tabcur cursor for
select name
from tablename
declare @.name nvarchar(100)
open tabcur
fetch next from tabcur into @.name
while @.@.fetch_status = 0
begin
... processing
fetch next from tabcur into @.name
end
deallocate tabcur
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"Opal" <anchi.chen@.gmail.com> wrote in message
news:1146630209.489346.65260@.j73g2000cwa.googlegroups.com...
> Hi guys,
> Is there a trivial way for looping through each record in a table
> that's equivalent to plsql's
> for r1 in (select * from tablename) loop
> v_name := r1.name;
> ...
> end loop
> ?
> I've tried the cursor approach but realised I'll need to define a
> variable for each column inside the table. So am currently looking for
> an alternative.
>
> Thanks in advance.
>|||Hi,
Thanks Helmut. My concern with this approach (which is similar to what
I've done but with the cursor approach) is because my table contains
more than 20,000 rows, this means I'll be executing the select
statement >20,000 times.
But thanks anyway. It seems like there's not other ways around it.
Regards|||Thanks Tony,
Yes, but because I'll need to address every single columns in my table
(which is more than 20).
What I'm trying to do is actually copying a table from another database
into 2 tables. For example, say if the primary table has 5 columns,
I'll need to insert the first 2 columns into table 1 and the last 3
columns into table 2. And hence need to loop through an entire table
to access every single column.
Thanks|||I usually table variable than cursor.
DECALRE @.t TABLE (ID Identity,...,)
INSERT @.t SELECT ..,FROM Employees
SELECT @.max_cnt=COUNT(*) FROM @.t
WHILE(@.i<=@.max_cnt)
BEGIN
SELECT .., FROM @.t WHERE ID=@.i
..,
SET @.i=@.i+1
END
"Opal"?? ??? ??:

> Hi guys,
> Is there a trivial way for looping through each record in a table
> that's equivalent to plsql's
> for r1 in (select * from tablename) loop
> v_name := r1.name;
> ...
> end loop
> ?
> I've tried the cursor approach but realised I'll need to define a
> variable for each column inside the table. So am currently looking for
> an alternative.
>
> Thanks in advance.
>|||Oh, you don't need a cursor or owt like that, just use two insert
statements...
insert yourtable1( col1, col2 )
select col1, col2
from database1.dbo.tablename
insert yourtable2( col3, col4, col5 )
select col3, col4, col5
from database1.dbo.tablename
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"Anchi" <anchi.chen@.gmail.com> wrote in message
news:1146640265.804502.181830@.g10g2000cwb.googlegroups.com...
> Thanks Tony,
> Yes, but because I'll need to address every single columns in my table
> (which is more than 20).
> What I'm trying to do is actually copying a table from another database
> into 2 tables. For example, say if the primary table has 5 columns,
> I'll need to insert the first 2 columns into table 1 and the last 3
> columns into table 2. And hence need to loop through an entire table
> to access every single column.
> Thanks
>|||Thanks Hongju, this table variable is a feature that I've been
searching for the entire day without success.
I wonder if I can define it as an existing table such that I don't need
to list out the column types?
eg
DECLARE @.t TABLE <existing_table_name>
?
Thanks|||Thanks again Tony,
The examples you've shown me is exactly what I'm doing to avoid
declaring variables for each column.
However because yourtable1 has a new column with type Identity and
yourtable2 has a foreign key referencing yourtable1, I cannot just use
2 simple and clean sql statements.
I'll give Hongju's solution a try.
Thanks again, really appreciate your help.