[SQL2k5] Dynamic SQL Query Select On All User Tables

Jul 17, 2006

In one query, I would like to query every user table in a specified database for

SELECT TOP (3) COUNT_BIG([Event Count]) AS EventNum, [Target IP], MAX([Time]) as LastSeen
GROUP BY [Target IP]
ORDER BY EventNum DESC

How is this possible?

Please give examples, I am a beginner.

Assume every table has the same structure for columns event count, target ip, and time.


View 3 Replies


ADVERTISEMENT

Cant Connect To A SQL2K5 Express User Instance

Apr 18, 2008

(have reposted this here from Setup group, since no answers there)

Hi,
I am having a lot of trouble connecting to a user instance I've created. User instances have been enabled, Named pipes are also enabled. Running on XP SP2 with SQL2K5 SP2. I also have a standard SQL2005 instance running on this development machine.

When using SqlClient in a .Net2.0 application, my connection string to create the user instance looks like:
"Data Source=.SQLEXPRESS;integrated security=true;attachdbfilename=c: emp3500.mdf;user instance=true"

This connection succeeds and I see the new service being started etc. I also see the log file being created in my Application Data area. The log file all looks normal except for these lines at the very top of the report.

2008-04-15 16:29:13.57 Server Error: 17156, Severity: 16, State: 1.
2008-04-15 16:29:13.57 Server initeventlog: Could not initiate the EventLog Service for the key 'D69F8BFF-E490-47'.
2008-04-15 16:29:13.67 Server Error: 17054, Severity: 16, State: 1.
2008-04-15 16:29:13.67 Server The current event was not reported to the Windows Events log. Operating system error = 6(The handle is invalid.). You may need to clear the Windows Events log if it is full.
2008-04-15 16:29:13.67 Server Microsoft SQL Server 2005 - 9.00.3054.00 (Intel X86)



I can also run a query on the main express instance to check if a child instance is running:
SELECT owning_principal_name, instance_pipe_name, heart_beat FROM sys.dm_os_child_instances

gives:
METECHsteve \.pipeD69F8BFF-E490-47 sqlquery alive

If i try to connect via sqlcmd with this command line:
C:Program FilesMicrosoft Visual Studio 8VC>sqlcmd -S np:\.pipeD69F8BFF-E49
0-47 sqlquery -l 60

this will give:
HResult 0x57, Level 16, State 1
SQL Network Interfaces: Connection string is not valid [87].
Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections..
Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.


If i try to connect via SSMS using the pipe name above and everything else defaulted, i get the following error:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 25 - Connection string is not valid) (.Net SqlClient Data Provider)


Both errors are pretty similar. I am running this locally, so I suspect the 'remote connection' error text is a red herring. The connection string is pretty minimal so I cant see why the connection string is invalid.

Heres another wierd thing. It used to consistently work. It now consistently fails. I have also tried creating a VM with SQLX. Now that works initially but once it fails, it seems to fail consistently. Reboots of the VM dont seem to fix it. That sort of leads me to believe that I've done something to my server (ie a setting somewhere).

Any help getting this connection issue sorted would be appreciated!

Thanks,
Steve

View 5 Replies View Related

Dynamic Query Calling User Defined Function

Apr 19, 2006

I have the following procedure, that calls a Padding function to pad characters to a field.

Here is what the procedure looks like

Code:

CREATE PROCEDURE [dbo].[Pad_Left]

@Table VARCHAR(255),
@Column VARCHAR(255),
@PadChar CHAR(1),
@PadToLen INT

AS

DECLARE @Query Varchar(5000)

SET @Query = 'UPDATE ' + @Table + '

SET ' + @Column + ' = dbo.Function_PadLeft(' + @Column + ', ''' + @PadChar + ''', ' + @PadToLen + ')'

EXECUTE(@Query)
GO



When I run this I get the error

Server: Msg 245, Level 16, State 1, Procedure Pad_Left, Line 13
Syntax error converting the varchar value 'UPDATE Lincoln

SET baths = dbo.Function_PadLeft(baths, '0', ' to a column of data type int.

But when I just run this query, it works


Code:

CREATE PROCEDURE [dbo].[Pad_Left]

@Table VARCHAR(255),
@Column VARCHAR(255),
@PadChar CHAR(1),
@PadToLen INT

AS

UPDATE Lincoln

SET Baths = dbo.Function_PadLeft(Baths, '0', 4)

GO



Why would one work but not the other? I don't understand, as they are the same thing, just one calls the function dynamically?

I must be missing something very obvious

Thanks for any help!

View 2 Replies View Related

Dynamic SELECT Query

May 21, 2008

I need to implement a "dynamic" select query, in which I want that the type and the number of columns are variable/changeable. For example using the parameters of a stored procedures. I would have a client code (written in VB .NET) in which I would choose the columns that I want to display in a DataGridView.


How should I modify the SELECT line or the SP in general to solve the problem??


The code I need to modify is this:



Code Snippet
CREATE PROCEDURE uspSelect1
@iDataInit datetime = '01 gen 1753',
@iDataEnd datetime = '31 dic 9999',
@iArticle nvarchar(50) = N'%',
@iMachineNum smallint,
@iTypeMaterial nvarchar(50) = N'%',
@iNominalCount float,
@iOperator nvarchar(50) = N'%',
@iCustomer varchar(50) = N'%',
@iComments nvarchar(1000) = N'%',
@iLanguage nvarchar(50) = N'%'
AS
SELECT i.IDsample, i.Date, i.Article, i.MachineNum, i.TypeMaterial, i.NominalCount, i.Operator, i.Customer, i.Comments, i.Language, r.Um, r.CVm
FROM Identification i JOIN Reports r
ON (i.IDsample = r.IDsample)
WHERE i.Date BETWEEN @iDataInit AND @iDataEnd
AND i.Article LIKE @iArticle
AND i.MachineNum = ISNULL(@iMachineNum, i.MachineNum)
AND i.TypeMaterial LIKE @iTypeMaterial
AND i.NominalCount = ISNULL(@iNominalCount, i.NominalCount)
AND i.Operator LIKE @iOperator
AND i.Customer LIKE @iCustomer
AND i.Comments LIKE @iComments
AND i.Language LIKE @iLanguage
ORDER BY i.IDsample


Thank you.
Gabriele

View 8 Replies View Related

Ad-hoc Dynamic Query With Multiple Tables

Feb 8, 2005

Hi:
I'm trying to create an ad-hoc query on a Asp.net page for user. Besides the usual Boolean operators, Field Names, Comparison operators & Field Values, the ad-hoc query also involves multiple tables, eg [Customers] , [Members] & [Orders].

Now I have difficulties on writing a TSQL sp on how to take the dynamic query with different tables under consideration. User might simply query each individual tables (eg, Customers with age > 25) or combination of tables (eg, Membered Customers with Orders Amt > 1000 between 1/1/2005 - 1/31/2005)

I have look up a lot dynamic query on the net but all are with only 1 single table to hit. Could anyone give me a direction on how to write a dynamic query script with multiple tables under consideration? Much appreciated.

ps: The ad-hoc query only contains these defined tables, no other table will be involved.

View 3 Replies View Related

Error Executing Dynamic Select Query

Sep 29, 2007

Hi,

i have problem executing the dynamic query.

I have straight forward query as below and works fine


declare @count bigint

declare @varcount varchar(max)

set @varcount ='5'

If convert(bigint, @varcount) <> 4

print ' not 4 '

else

print 'Its 4'



Here is my dynamic query. The number of records (@No ) and the table name ( @table ) will be available for me as parameters to my stoped proc



declare @count bigint

declare @varcount varchar(max)

declare @tempTable varchar(max)

declare @vsSql varchar(max)

declare @No bigint

set @No = 5

set @table = 'sam'

set @varcount = ''

select @vsSql = 'declare @varcount varchar(max); select @varcount = count(*) from ' + @table + '; If convert(bigint,@varcount) <> ' + @No + ' raiserror(' +'mismatch, 11,1' +')'



When executed it throws the follwing error


Msg 8114, Level 16, State 5, Line 10

Error converting data type varchar to bigint.



Can anyone point out what to change in the query to work

~mohan

View 1 Replies View Related

SQL Security :: How To Grant Two Tables (select Only) Access To New User

May 5, 2015

i want to create new sql user and grant him two tables access. we have several databases created on same server so we want to allow only two table in ABC database. user should not be able to see other databases and their tables. And user also should not be able to access any other tables in ABC database except two tables.

is there any query to deny all tables in schema for all clauses (Select, Update, Insert) then grant two tables to user with select clause?

View 17 Replies View Related

SQL Server 2014 :: How To Call Dynamic Query Stored Procedure In Select Statement

Jul 23, 2014

I have created a stored procedure with dynamic query and using sp_executesql . stored procedure is work fine.

Now i want to call stored procedure in select statement because stored procedure return a single value.

I search on google and i find openrowset but this generate a meta data error

So how i can resolve it ???

View 7 Replies View Related

Query To Retreive User Tables In Sql Db

Jan 2, 2004

Is there a way to create a query that will return all user tables inside a sql db

Thanx

View 4 Replies View Related

Query To Get All User Tables With Columns

Jul 20, 2005

Hi,I tried to create a simple view as followsCREATE VIEW V_ALL_USERTABLE_COLUMNSAS(SELECTOBJ.NAME as TableName,COL.NAME as ColName,TYP.NAME AS TYPEFROMSYSOBJECTS OBJ,SYSCOLUMNS COL,SYSTYPES TYPWHEREOBJ.TYPE = 'U'AND OBJ.ID = COL.IDAND COL.TYPE = TYP.TYPE)Combined with consistent naming conventions I will use this view toeasily find foreign keys; a laSELECT *FROM V_ALL_USERTABLE_COLUMNSWHERE ColName LIKE ('%user_id')There is something wrong with my view definition that I don't getthough; it doesn't return all the columns. I have a table with thefollowing definitionCREATE TABLE [dbo].[c_messages]([cid] [int] IDENTITY (1, 1) NOT NULL ,[touser_id] [int] NULL ,[tosession_id] [char] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[fromuser_id] [int] NOT NULL ,[message] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOTNULL ,[message_read] [bit] NOT NULL ,[logout] [bit] NULL) ON [PRIMARY]GOThe problem is that the select I used to define the view doesn'treturn the touser_id column. I have sort of a sneaking suspicion thatthe problem has to do with joining syscolumns.type to systypes.type,but I don't know what to do instead (I'd really like to include thetype; it's useful if I ever changed the type of a primary key and wantto check that I also changed all the foreign keys).Any help would be appreciated!

View 1 Replies View Related

The User's Select Query Should Be Denied But It Didn't?

Nov 24, 2006

hi ..

my problem is
i create a user in sqlserver from enterprise manager as follows:-

1- goto logins and new login
2-type a name and choose sqlserver authentication and type a password
3- from server roles tab i choose system administrators
4 from database access i choose the database i need that user to connect to .and OK
5-i goto database node in enterprise manager and select the database and the table
and double click on it and choose permissions and de-select the SELECT privilige

then i use ADO to connect to sqlserver through that user and when i select(SQL query) the table the data appeared normally !!!! and it suppose to give me exception

thanks in advance.

View 6 Replies View Related

Query - Select Two Tables Where A.id=b.id

Dec 28, 2007

Hi,my query is:SELECT a.symbol_art,b.node_keyFROM artykuly a, art_podz bWHERE a.symbol_art=b.symbol_art------------- -------------------table: artykuly table art_poda.symbol_art b.symbol_artAA-0001 AA-0001 = record okAA-0002 NULL = >>>>>>>>I want to view diferencerecords symbol_art in two tablesHow select all a.symbol_art where in table art_podz b.symbol_art is no exists?tnx.Tom

View 2 Replies View Related

Declaring A Table Variable Within A Select Table Joined To Other Select Tables In Query

Oct 15, 2007

Hello,

I hope someone can answer this, I'm not even sure where to start looking for documentation on this. The SQL query I'm referencing is included at the bottom of this post.

I have a query with 3 select statements joined together like tables. It works great, except for the fact that I need to declare a variable and make it a table within two of those 3. The example is below. You'll see that I have three select statements made into tables A, B, and C, and that table A has a variable @years, which is a table.

This works when I just run table A by itself, but when I execute the entire query, I get an error about the "declare" keyword, and then some other errors near the word "as" and the ")" character. These are some of those errors that I find pretty meaningless that just mean I've really thrown something off.

So, am I not allowed to declare a variable within these SELECT tables that I'm creating and joining?

Thanks in advance,
Andy



Select * from

(

declare @years table (years int);

insert into @years

select

CASE

WHEN month(getdate()) in (1) THEN year(getdate())-1

WHEN month(getdate()) in (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) THEN year(getdate())

END

select

u.fullname

, sum(tx.Dm_Time) LastMonthBillhours

, sum(tx.Dm_Time)/((select dm_billabledays from dm_billabledays where Dm_Month = Month(GetDate()))*8) lasmosbillingpercentage

from

Dm_TimeEntry tx

join

systemuserbase u

on

(tx.owninguser = u.systemuserid)

where

Month(tx.Dm_Date) = Month(getdate())-1

and

year(dm_date) = (select years from @years)

and tx.dm_billable = 1

group by u.fullname

) as A

left outer join

(select

u.FullName

, sum(tx.Dm_Time) Billhours

, ((sum(tx.Dm_Time))

/

((day(getdate()) * ((5.0)/(7.0))) * 8)) perc

from

Dm_TimeEntry tx

join

systemuserbase u

on

(tx.owninguser = u.systemuserid)

where

tx.Dm_Billable = '1'

and

month(tx.Dm_Date) = month(GetDate())

and

year(tx.Dm_Date) = year(GetDate())

group by u.fullname) as B

on

A.Fullname = B.Fullname

Left Outer Join

(

select

u.fullname

, sum(tx.Dm_Time) TwomosagoBillhours

, sum(tx.Dm_Time)/((select dm_billabledays from dm_billabledays where Dm_Month = Month(GetDate()))*8) twomosagobillingpercentage

from

Dm_TimeEntry tx

join

systemuserbase u

on

(tx.owninguser = u.systemuserid)

where

Month(tx.Dm_Date) = Month(getdate())-2

group by u.fullname

) as C

on

A.Fullname = C.Fullname

View 1 Replies View Related

Select Statement Help:How Do I Query Two Tables

Mar 20, 2006

How do I Query two tables and minus the result to be displayed in a gridview.  I will appreciate all the help that I can get in this regard. Find below my two select statement
1st Select StatementDim SelectString As String = "SELECT DISTINCT [Course_Code], [Course_Description], [Credit_Hr], [Course_Type], [Course_Method] FROM [MSISCourses] WHERE (([Course_Type] = Core) OR ([Course_Type] = Information Integration Project) "If radBtnView.Checked = True ThenSelectString = SelectString & " OR ([Course_Type] = 'Knowledge')"End IfIf chkGView.Checked = True ThenSelectString = SelectString & " OR ([Specialization] = 'Data Management')"End IfIf chkGView2.Checked = True ThenSelectString = SelectString & " OR ([Specialization] = 'General')"End IfIf chkGView1.Checked = True ThenSelectString = SelectString & " OR ([Specialization] = 'Electronic Commerce')"End IfIf chkGView3.Checked = True ThenSelectString = SelectString & " OR ([Specialization] = 'Network Administration and Security')"End IfIf chkGView4.Checked = True ThenSelectString = SelectString & " OR ([Specialization] = 'Healthcare Information Systems')"End IfSqlDataSource3.SelectCommand = SelectString
2nd Select Statement"SELECT DISTINCT [Co_Code], [Co_Description], [Cr_Hr], [Co_Type], [Co_Method] FROM [StudentCourses] WHERE ([Co_Code] = StdIDLabel)"
my gridview<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="Course_Code" DataSourceID="SqlDataSource3" GridLines="Horizontal"><Columns><asp:BoundField DataField="Course_Code" HeaderText="Course_Code" ReadOnly="True" SortExpression="Course_Code" /> <asp:BoundField DataField="Course_Description" HeaderText="Course_Description" SortExpression="Course_Description" /> <asp:BoundField DataField="Credit_Hr" HeaderText="Credit_Hr" SortExpression="Credit_Hr" /> <asp:BoundField DataField="Course_Type" HeaderText="Course_Type" SortExpression="Course_Type" /> <asp:BoundField DataField="Course_Method" HeaderText="Course_Method" SortExpression="Course_Method" /> </Columns></asp:GridView>

View 6 Replies View Related

Select Query For Retrieving Data Using 3 Tables?

Apr 21, 2015

I want to retrieve the data from table "Document" and i need to check the below condition using 3 tables.

Document.ID=Project.ID=Group.ID

Here Project and Group is an another table.

Query : Select Document.Name from Document, Group, Project where
Document.ID = Group.ID and Document.ID= Project.ID.

is this right a way?

View 3 Replies View Related

How Do We Determine Which User Database Tables Are Mostly Retrieved By User Or Modified By User?

May 22, 2008



Hi,
Please give the T-SQL script for this ? Thanks

Shanth


View 4 Replies View Related

Does It Locks Database/tables When Only Select Query Comes In SQLTransaction

Jul 12, 2006

Hi,

I want to make SQLTransaction as global and use it checking the State.
But then where there are Only Select queries are going to fire, it will open transaction.

So, Does it locks database/tables when Only Select query comes in SQLTransaction.

If you have another successful way of doing this, Please suggest.

Thanking you.

tats

View 8 Replies View Related

T-SQL (SS2K8) :: Select Query To Pull Required Data From 3 Tables

Mar 19, 2014

I have three tables EmpIDs,EmpRoles and LatestRoles. I need to write a select Query to get roles of all employees present in EmpIDs table by referring EmpRoles and LatestRoles.

Where I stuck : The condition is first look into table EmpRoles and if it has more than one entry for a particular Employee ID than only need to get the Role from LatestRoles other wise consider the role from EmpRoles .

Example:

Create Table #EmpIDs (
EmplID int
)
Create Table #EmpRoles (
EMPID int,

[Code] ....

Employee ID 2 is having two roles defined in EmpRoles so for EmpID 2 need to fetch Role from LatestRoles table and for remaining ID's need to fetch from EmpRoles .

My Final Output of select query should be like below.

EmpID Role
1 Role1
2 Role2
3 Role1

View 5 Replies View Related

Query To Select Multiple Tables In Dataset Through ODBC Connection

Apr 10, 2007

Hi there,



I have a MS Access database (mdb) containing the following tables:



Crime

Criminal

CrimeCommitted

Hideout

CriminalType



The Criminal table contains information about each criminal and the CrimeCommitted table contains information about the specific crimes. I've written the following query to return only the latest crime committed by each criminal:




Code Snippet



SELECT Criminal.CriminalID, Criminal.Firstname, Criminal.Lastname, Criminal.Nickname, Criminal.Gender, Criminal.DOB, Criminal.Eyes, Criminal.Complexion, Criminal.Weight, Criminal.Height, Criminal.Build, Criminal.Scars, Criminal.Occupation, Criminal.CrimeOrgID, Criminal.IQ, Criminal.Hideout, Criminal.CriminalType, Max(CrimeComitted.Date) AS Last_Crime_Comitted
FROM Criminal INNER JOIN CrimeComitted ON Criminal.CriminalID=CrimeComitted.CriminalID
GROUP BY Criminal.CriminalID, Criminal.Firstname, Criminal.Lastname, Criminal.Nickname, Criminal.Gender, Criminal.DOB, Criminal.Eyes, Criminal.Complexion, Criminal.Weight, Criminal.Height, Criminal.Build, Criminal.Scars, Criminal.Occupation, Criminal.CrimeOrgID, Criminal.IQ, Criminal.Hideout, Criminal.CriminalType;







This query works fine for obtaining the Criminal table data, but once i've include CrimeCommitted.Country in the SELECT statement, the data returned contained all the crimes committed by each criminal (i just need the latest crime).



The query doesn't work when another table, other than Criminal, is selected. How can i obtain the columns in the CrimeCommitted table in this query?

View 2 Replies View Related

Dynamic Tables Names And Temporary Tables Options

Oct 5, 2007

Firstly I consider myself quite an experienced SQL Server user, andamnow using SQL Server 2005 Express for the main backend of mysoftware.My problem is thus: The boss needs to run reports; I have designedthese reports as SQL procedures, to be executed through an ASPapplication. Basic, and even medium sized (10,000+ records) reportingrun at an acceptable speed, but for anything larger, IIS timeouts andquery timeouts often cause problems.I subsequently came up with the idea that I could reduce processingtimes by up to two-thirds by writing information from eachcalculationstage to a number of tables as the reporting procedure runs..ie. stage 1, write to table xxx1,stage 2 reads table xxx1 and writes to table xxx2,stage 3 reads table xxx2 and writes to table xxx3,etc, etc, etcprocedure read final table, and outputs information.This works wonderfully, EXCEPT that two people can't run the samereport at the same time, because as one procedure creates and writesto table xxx2, the other procedure tries to drop the table, or read atable that has already been dropped....Does anyone have any suggestions about how to get around thisproblem?I have thought about generating the table names dynamically using'sp_execute', but the statement I need to run is far too long(apparently there is a maximum length you can pass to it), and evenbreaking it down into sub-procedures is soooooooooooooooo timeconsuming and inefficient having to format statements as strings(replacing quotes and so on)How can I use multiple tables, or indeed process HUGE procedures,withdynamic table names, or temporary tables?All answers/suggestions/questions gratefully received.Thanks

View 2 Replies View Related

SQL 2012 :: How To Grant A New User Same Direct Privilege To Tables As Existing User

Feb 18, 2014

I am relatively new to sql developer. There is a new user that just joined our organization. I am trying to grant him the same direct grants privilege to the tables that an existing user has. The existing user has a ton of direct table access privileges and it will take days if I had to do each grant one by one like: grant select,insert,delete,update on 'table name' to 'user id'. Is there a way of copying or inserting an existing user's privilege and granting it to a new user.

View 2 Replies View Related

Is There A Way To Show A User-friendly Error When User Did Not Select A Required Parameter ?

Apr 9, 2007

Hi all,



I was wondering whether there is a way to show the user an error when the user did not select a specific parameter.



In my case, I have two optional parameters. The user has to select either one to view the report. If the user does not select either one, I would like to show some sort of an error page indicating so. However, all i am getting is a complete blank with no report in sight. I as a developer know this is an error as a result of missing parameters, but i was wondering whether I could produce a page or direct it to a page so that the user doesn't go all horrified at an empty page ?



Thanks

Bernard

View 4 Replies View Related

Reporting Services :: Select Text Field Dataset Based On User Select Option?

Aug 4, 2015

I have a report that uses different datasets based on the year selected by a user.

I have a year_id parameter that sets a report variable named dataset_chosen. I have varified that these are working correctly together.

I have attempted populating table cell data to display from the chosen dataset. As yet to no avail.

How could I display data from the dataset a user selects via the year_id options?

View 4 Replies View Related

Is A Dynamic User Specified Connection Possible

Jul 17, 2007

I work on a system that is mirrored. there is production, and UAT(user acceptance testing). We have to do repetitive tasks on the systems. I want to write an application to make those tasks easier, using integration services. I would rather have one app and be able to specify which database server the dtsx packages would use each time. is this possible in dtsx packages, to specify a particular sql server? the tables and databases would not change between production and uat

View 7 Replies View Related

Dynamic Filtering By User At Runtime?

Feb 3, 2008



I have a project where there are millions of records. For sake of example, let's use the White Pages.

One of the reports my client wants generated is a contact list. The contact list contains name, address, city, state, zip, phone, and several other key data elements.

Naturally, the client wants to be able to sort on each of those elements (easy to do.)

They also want to be able to filter the resultset the report shows, dynamically, at runtime (not so easy, I'm finding).

So, for example, one person may want to run the report and have the results only show people in PA. Another person may run a report and show all the people who are in Boston, MA. Yet another person may want everyone with the last name of "Smith".

Ultimately, the client wants to be able to filter results by virtually every day field displayed on the report (and some fields which are not!)

I've dug around the documentation for Reporting Services, and I readily admit I am a newbie. I cannot see any way to dynamically filter the resultset used to generate the report, other than using "Report Parameters".

The problem with Report Parameters, from what I can tell, is they also require me to have scalar expressions in a WHERE clause in the dataset. So, for example, if I wanted to let people filter on lastname, I would need a "WHERE LASTNAME LIKE @LastNameReportParameter" -- which works ok, as long as the parameter isn't null, of course, so I really have to do something like 'WHERE LastName LIKE ISNULL(@LastNameReportParameter, '%')"

With, literally, a dozen different fields on this report, I don't see where that is a real option -- I literally have to program a WHERE clause that has a dozen elements, some of which are numeric (not alpha), and thus LIKE doesn't work (AGE = 37) unless I get into completed gyrations (WHERE ISNULL(CAST(AGE AS VARCHAR), '') LIKE ISNULL(@AgeParameter, '%')

This seems to be incredibly complicated, and I cannot imagine there isn't an easier way to allow users to filter the resultsets on the reports generated by Report Server. Is there something I am missing?

Also, it has to be something I can address programatically, since the client wants a fairly 'seamless' front end (in C#) where users can simply click a radio button (to select a field to filter by) and type in a value (to filter on) prior to displaying the report in a reportviewer control.

Is there a way to dynamically program a filter expression and pass it to the report server, something akin to a filter expression on a BindingSource?


Any thoughts on this matter would be helpful, or pointers to online documentation, as I'm sort of out of ideas and cannot find anything in the docs. Thanks!

View 6 Replies View Related

Dynamic Login &&amp; User Creation

Mar 27, 2006

Hello. I'm trying to create a new login and username inside a trigger using variables.

This code works:

create login testUserName with password = 'testPassword'

The problem comes when I try to use variables for the username and password like this.

create login @username with password = @password

Does anybody know how to get around this problem?

BTW, the error message it gives is this, but I really doubt that semicolons have anything to do with it. If I literally type my data in the create login call it works fine, but when I use variables it doesn't.

Msg 102, Level 15, State 1, Line 14

Incorrect syntax near '@username'.

Msg 319, Level 15, State 1, Line 14

Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.

View 8 Replies View Related

How To Create Multiple Tables On The Fly So That Every User Each Has His/her Own Set Of Tables?

Aug 12, 2006

Hello all,

Being still a relative newcomer to SQL Server (people may say I'm trying to take on too much being somewhat inexperienced once they read about the problem I'm trying to tackle, but alas...) I'm running into the following problem: I need to create tables in my user database on the fly (using Stored Procedures) so that each table can be created many times in the database but only once for every user. The tables should be named something like "username.Table1", "username.Table2" etc. as opposed to "dbo.Table1". I then want to use the stored procedure from .NET/C# in my web application, so that i can create the complete set of usertables for each of my clients.

Now, I tackled the stored procedure part (that is, it creates all the tables I need with all the parameters I want) and am able to use it from my web application (which took some time to learn but proved quite easy to do), but I cannot seem to get it coupled to the current user (instead of the dbo). Every time I trie, the tables are created as dbo.Table1 and when I try to create a new set, it gives a warning ("table with name such and so already exists..."). I made sure to log in as an authenticated user (using forms authentication) before trying to create the tables but this gives the aforementioned result.

What am I doing wrong? I use Visual Web Developer Express, SQL Server 2005 Express and IIS version 5.1

Please help :-D

Greetingz,

DJ Roelfsema

View 6 Replies View Related

Dynamic WHERE Operator Based On User Input

Oct 17, 2007

Let's say I have a table with 3 fields: an ID field (primary key, set as an id field, etc.), a Name field (nvarchar50), and an Age field (int). I have a form that has three elements:
DropDownList1: This drop down list contains 3 choices- "=", ">", and "<".
Age: This text box is where someone would enter a number.
Button1: This is the form's submit button.
I want someone to be able to search the database for entries where the Age is either equal to ("="), greater than (">"), or less than ("<") whatever number they enter into TextBox1.
The code-behind is shown below. The part I'm confused about is that if I load this page, the query works the -first- time. Then, if I try to change the parameters in the form and submit it, I get the following error:
"The variable name '@Age' has already been declared. Variable names must be unique within a query batch or stored procedure."
Any help would be appreciated.
Here is what I'm using in my code behind:
    protected void Button1_Click(object sender, EventArgs e)    {        System.Text.StringBuilder sb = new System.Text.StringBuilder();        sb.Append("SELECT * FROM People WHERE Age ");        switch (DropDownList1.SelectedValue)        {            case "=":                sb.Append("= ");                break;            case ">":                sb.Append("> ");                break;            case "<":                sb.Append("< ");                break;        }        sb.Append("@Age");        SqlDataSource1.SelectCommand = sb.ToString();        SqlDataSource1.SelectParameters.Add("Age", TypeCode.Int32, Age.Text);    }

View 7 Replies View Related

Multiple Tables Select Performance - SQL 2005 - Should It Take 90 Seconds For A Select?

Dec 4, 2007

I have a problem where my users complain that a select statement takes too long, at 90 seconds, to read 120 records out of a database.
The select statement reads from 9 tables three of which contain 1000000 records, the others contain between 100 and 250000 records.
I have checked that each column in the joins are indexed - they are (but some of them are clustered indexes, not unclustered).
I have run the SQL Profiler trace from the run of the query through the "Database Engine Tuning Advisor". That just suggested two statistics items which I added (no benefit) and two indexes for tables that are not involved at all in the query (I didn't add these).
I also ran the query through the Query window in SSMS with "Include Actual Execution Plan" enabled. This showed that all the execution time was being taken up by searches of the clustered indexes.
I have tried running the select with just three tables involved, and it completes fast. I added a fourth and it took 7 seconds. However there was no WHERE clause for the fourth table, so I got a cartesian product which might have explained the problem.
So my question is: Is it normal for such a type of read query to take 90 seconds to complete?
Is there anything I could do to speed it up.
Any other thoughts?
Thanks

View 7 Replies View Related

Dynamic Tables.

Apr 30, 2004

hello everyone,

Thank you Darrell for your help on my "Firehose" problem.

Well, I have another question for everyone. I have three tables with the same columns: Products, Products_Sold, and Products_StandBy. I have a Stored Procedures that gets the products: Products_Get, Products_Sold_Get, and Products_StandBy_Get. I want to be able to only have one stored procedure that gets from all tables depending on what @Table variable I give it.

I tried the following, but it didn't work:


CREATE Procedure CMRC_Products_Get
@Table
AS
CREATE TABLE #TempTable
(
ProductID int,
Chest nvarchar (50),
ItemSize nvarchar (50)
)

INSERT INTO #TempTable
(
ProductID,
Chest,
ItemSize
)
SELECT
ProductID,
@Table.Chest,
CMRC_WomensSizes.ItemSize
FROM
@Table INNER JOIN
CMRC_WomensSizes ON @Table.Chest = CMRC_WomensSizes.Chest


I get an error message on the line: "@Table.Chest,"

So, my question would now be, how do I go about doing what I'm attempting here? Anybody? Thanks ahead for any help.

Sincerely,


Alec

View 1 Replies View Related

Dynamic Tables???

Jun 20, 2008

hi all.

i just want to know if i can create a dynamic table. i mean a table which expands itself based on the requirement.

or a table can only be static???





Cheers!!!
Bel.

View 5 Replies View Related

How To Design Dynamic Reports Based On User's Choice

Dec 13, 2006

Hi all,

I'm a beginner to Report Services, and have tons of questions.

Here's the first one:

if the reports are created based on the condition that the user selects, how can I create the reports with Report Services?

For example,

the user can select the fields that will be shown on the reports, as well as the group fields, the sort fields and restrict fields. So I would not be able to pre-create all possible reports and deploy them to the report server, and I think I should create the reports dynamicly based on what the user select.

Could someone tell me how to do it (create and deploy the reports)?

Thanks a million!

Jonee

View 1 Replies View Related

Dynamic OLE DB Connection String With Static User ID And Password

Apr 30, 2008

I'm trying to setup a dynamic ole db connection using the SA user ID, it has to be dynamic because the server name will change and it has to be SA because we're pulling information from system databases that some users don't have access to.

If I setup a regular static connection using SA credentials it works like a charm of course. When I create an expression to use the User:erver variable it doesn't work, it throws an error message saying that "The login failed for user sa" among other things, I'm thiking that the sa's password is not being saved.

Where exactly do I place a password for dynamic connections using sql server users? On the connection string? On the password property of the source? Any ideas?

View 1 Replies View Related







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