How To Sort A Table With A Parameter

Jan 8, 2007

I have a "Sales shipments" report with several colums. I want a parameter for the user so he choose how to sort. I have two colums in my report I want to sort on: ItemNumber and DeliveryDate.

I added a Report Parameter UserSort with two labels (and values): Item (ItemNumer) and Date (DeliveryDate).

Then I tried to set the sorting

View 6 Replies


ADVERTISEMENT

Stored Procedure With A Sort Parameter

Apr 20, 2006

I have a SQL Server 2005 Stored Procedure that takes a parameter to sort on:
-----------------------------------------------------------------
ALTER PROCEDURE [dbo].[GetAllApplications_Sorted]

@sortType varchar(25)

AS
SET NOCOUNT ON;
SELECT aev.ApplicationID,
aev.ApplicationName,
aev.EventMessage,
aev.MachineID,
aev.MachineName,
aev.EventLevel,
ellu.EventImg,
ellu.EventLevelID,
dbo.GetMaxEventLevelByApplicationID(aev.ApplicationID) AS maxEventLevel
FROM dbo.ApplicationEventView aev, dbo.EventLevelLookUp ellu
WHERE ellu.EventLevelID=dbo.GetMaxEventLevelByApplicationID(aev.ApplicationID)
AND aev.EventLevel=ellu.EventLevel
ORDER BY ellu.EventLevelID + ' ' + @sortType
-----------------------------------------------------------------
Problem is I keep getting this error:
Conversion failed when converting the varchar value 'desc' to data type int.
And I can't figure out why...
 
Thanks,
 
Doug

View 1 Replies View Related

Pass A Parameter For Sort Order

Jan 4, 2005

Is there a way to pass a parameter into a stored procedure to set the sort order.

I have tried things like

ORDER by EmployeeID @direction

where @direction is a varchar with a value of 'desc' and I get an error.

I do not want to dynamically create the sql and use sp_executesql.
I have already done it this was but I am looking for a better solution.

View 1 Replies View Related

Sort Displayed Multi Parameter

Jul 25, 2007

Hi all,



Is it possible to sort the values in a multi-paramter.

Notice, i'm am working with a model.

For the moment my multivalue selectionbox looks like this

B

D

H

A

C

F



And of course i would like it to be

A

B

C

D

E

F



Is there a way to do this ?



Any help is welcome.

Vinnie

View 4 Replies View Related

Pass Sort Parameter In Stored Procedure

Oct 29, 2007

hi,
i searched a lot to find how to pass an orderBy parameter finally i used a case block in my code and it works now how can i add a second parameter for ascending and descending order(@sortAscOrDesc)
when i use it after the end of case statement i get error
here is my sp:CREATE PROCEDURE [userPhotos]
@userID int,@orderBy varchar(100)
ASSELECT ID,UserID,Photo,ALbumID,Title,views,date_added from userAlbumPic where userID=@userID and albumID=0 order by
case @orderBy
when 'date_added' then date_added
when 'views' then [views]
else date_added
end
GO

View 7 Replies View Related

Sort Order Via Parameter-now Security Issue

Mar 19, 2007

we are firing this from my asp page, what i can't work out how to do is pass a sort order via parameter to my stored procedure.
Any Help appreciated

Nigel

set conn = CreateObject("ADODB.Connection")

conn.open MM_fc_conn_STRING

sql = "EXEC Sproc_01020_Select_WebUser" & " @UserLoginName='" & Request.Form("Username") & "'"

set Recordset1 = conn.execute(sql)

View 17 Replies View Related

Sort Expression As Store Procedure Parameter?

Jul 23, 2005

Can I pass a sort expression into a store procedure as a parameter? Iwant to do sth like the following but do not know if it's possible.Maybe I need some tricks to work around?CREATE Procedure SelectAllRoles(@SortExpression varchar(20))ASIF @SortExpression <> ''THENSELECT Id, Name, Name2, LastUpdatedFROM [Role]ORDER BY @SortExpressionELSESELECT Id, Name, Name2, LastUpdatedFROM [Role]GOThanks!Zhu Ming

View 1 Replies View Related

Stored Procedure Sort Parameter Doesnt Work

Jul 22, 2006

Hello, I am trying to make this.

CREATE PROCEDURE [dbo].[P_SEL_ALLPERSONAS]

@nmpersona int,

@sortorder varchar(20)



AS

BEGIN

select nmpersona, dsprimernombre, dssegundonombre,

dsprimerapellido, dssegundoapellido

from personas

order by @sortorder

END



But I got this error. Please help



Msg 1008, Level 16, State 1, Procedure P_SEL_ALLPERSONAS, Line 13

The SELECT item identified by the ORDER BY number 1 contains a variable as part of the expression identifying a column position. Variables are only allowed when ordering by an expression referencing a column name.

View 5 Replies View Related

Reporting Services :: Page Break Based On Sort Parameter Value In SSRS 2008

Nov 19, 2015

I have a SSRS report with data in below format.

ID       Name    Date
1           A         null
2           B        01/01/2012
3           C        01/02/2013

Also, I have a sort parameter @sort and values are (Name, ID, Date)

I want to apply page break whenever @sort=Name. There should be no page break when user selects @sort = ID or Date. Page break should happen only when @sort value = Name

it should be like this...

Page 1:
ID       Name    Date
1           A         null
Page 2:
ID       Name    Date
2          B         01/01/2012
Page 3:
ID       Name    Date
3           C        01/02/2013

I need achieving the above task.

View 2 Replies View Related

Automatically Sort Table When Table Is Opened In Project

Jul 20, 2005

Hi all,We recently upsized two Microsoft Access Databases to SQL. We'reusing an ADP (2002) as the front end.All the conversion issues have been resolved, except for one:Whenever we insert a record into a table, the table isn't sorted byprimary key like I would expect. Instead, the record can be found atthe end of the table. This makes finding a particular record(especially as time goes on) very difficult.I've tried eliminating all indexes except for the primary key, andalso writing AFTER INSERT triggers, but the table still does not sortcorrectly.Any suggestions would be greatly appreciated!Matt

View 4 Replies View Related

Sort Table

May 10, 2006

Hello,
Is there a way to re sort data in a table? based on ID.

The
SORT TABLE tlb_Name ON ID Asc
is not working?

Thank you very much.

View 6 Replies View Related

Table Will Not Sort

Oct 4, 2007

I have quite a long SP which is made up of various tables, temp tables, etc.

I am creating 11 physical tables which i am using to create a DTS package to auto output to an excel spreadsheet (template for a report).

The problem is although i have used ORDER BY statements to sort the data in ascending order the data isnt sorted.

Heres an example of one of the table outputs

--Create Table of Managers
DELETE FROM Weekly_Term_Code_Output7
INSERT INTOWeekly_Term_Code_Output7
SELECT #Temp_Agent.Manager
FROM #temp5 INNER JOIN
#Temp_Agent ON #temp5.agent_login = #Temp_Agent.agent_login
WHERE (NOT (#Temp_Agent.Manager IS NULL))
GROUP BY #Temp_Agent.Manager
ORDER BY #Temp_Agent.Manager



ive also tried placing an order by statement in the output to excel in the DTS package but this also doesnt work?

Any ideas anyone??

View 8 Replies View Related

Dynamic Sort Column And Sort Order Not Working

Aug 7, 2007

I am trying to set sorting up on a DataGrid in ASP.NET 2.0.  I have it working so that when you click on the column header, it sorts by that column, what I would like to do is set it up so that when you click the column header again it sorts on that field again, but in the opposite direction. I have it working using the following code in the stored procedure:   CASE WHEN @SortColumn = 'Field1' AND @SortOrder = 'DESC' THEN Convert(sql_variant, FileName) end DESC,
case when @SortColumn = 'Field1' AND @SortOrder = 'ASC' then Convert(sql_variant, FileName) end ASC,
case WHEN @SortColumn = 'Field2' and @SortOrder = 'DESC' THEN CONVERT(sql_variant, Convert(varchar(8000), FileDesc)) end DESC,
case when @SortColumn = 'Field2' and @SortOrder = 'ASC' then convert(sql_variant, convert(varchar(8000), FileDesc)) end ASC,
case when @SortColumn = 'VersionNotes' and @SortOrder = 'DESC' then convert(sql_variant, convert(varchar(8000), VersionNotes)) end DESC,
case when @SortColumn = 'VersionNotes' and @SortOrder = 'ASC' then convert(sql_variant, convert(varchar(8000), VersionNotes)) end ASC,
case WHEN @SortColumn = 'FileDataID' and @SortOrder = 'DESC' THEN CONVERT(sql_variant, FileDataID) end DESC,
case WHEN @SortColumn = 'FileDataID' and @SortOrder = 'ASC' THEN CONVERT(sql_variant, FileDataID) end ASC  And I gotta tell you, that is ugly code, in my opinion.  What I am trying to do is something like this:  case when @SortColumn = 'Field1' then FileName end,
case when @SortColumn = 'FileDataID' then FileDataID end,
case when @SortColumn = 'Field2' then FileDesc
when @SortColumn = 'VersionNotes' then VersionNotes
end

case when @SortOrder = 'DESC' then DESC
when @SortOrder = 'ASC' then ASC
end  and it's not working at all, i get an error saying:  Incorrect syntax near the keyword 'case' when i put a comma after the end on line  5 i get: Incorrect syntax near the keyword 'DESC' What am I missing here? Thanks in advance for any help -Madrak 

View 1 Replies View Related

Simple Sort On A Table...

Jul 23, 2005

I am adding this to my c#.Net app...How can I sort all rows in a table?After it is sorted, will it remain so after i do a cnSQL.Close();so that when I then do a:string strSQL = "SELECT InvoiceNumber " +"FROM tblPrintInvoice " ;Is it still sorted for me to do a:drSQL.Read?Thanks,Trint

View 2 Replies View Related

ETL Sort Is Very Slow On A Big Table

Feb 11, 2008

Hi,

We have developped an ETL. For development we used small test files (10 000 rows) to test if it works correctly.
This runs in less then a minute

In Test we are using a file which contains all rows (7 million). We did twice a test and we first stopped the process after a week and the 2nd time we stopped the process after a weekend.

We are able to trace the problem to the point where it has to sort the tables.

The proces is pretty simple. We use two connectors to directly connect to the tables.
Then we have two blocks to sort the data. And then we have one block to merge the data.

Should we which to let SQL do the sorting ? Since it is in staging is has no index on that column. A select on the tables with an order by takes 3 minutes to return all those rows.

Any idea's ?

Also is there a page with the best practices for ETL ?

Constantijn

View 4 Replies View Related

Sort Table By Month

Sep 10, 2007



I have a table report that lists the prior 12 months of sales data. I'd like the report to display in reverse order from current month back. When I sort decedning by month it puts the months in reverse alphabetic order. How can I sort by numeric order?

Thanks.

View 1 Replies View Related

Sort Table Descending Without Orderby

Jun 24, 2008

can any one help me to sort a table on the basis of one colomn without using ORDER BY Desc.

Rahul Arora
07 Batch
NCCE Israna,


######################
IMPOSSIBLE = I+M+POSSIBLE

View 6 Replies View Related

Table Items Custom Sort

Feb 15, 2007

hello



i am currently trying to port a "Business Objects" report to SQL Server Reporting Services.

in B.O., there is a possibility to define the order of the table values by previewing the table values and moving them up or down.

Example : the dataset contains data for 3 items, so in the Custom Sort window, I will see these 3 items and I can order them by moving them up or down in a listbox.

is this possible to do in Reporting Services ?

View 9 Replies View Related

Interactive Sort For A Grouped Table

Aug 24, 2007

I'm trying out the interactive sort feature (and have searched high and low for this answer), but can not make the sorting work if I have the data in the table grouped. If I remove the group, the sorting works fine but the output is not acceptable due to the duplicated records in the list.

Can someone steer me in the right direction?

View 1 Replies View Related

Sort COLUMN NAMES Of A Table

Apr 25, 2008

Hi all,

Is there a way i can write a script that will sort the column names of my table?

Example:

Table 1 columns:
First_Name
Last_Name
Address
City
Country


I want to write a script that will sort them like this:

Address
City
Country
First_Name
Last_Name

View 4 Replies View Related

SQL 2012 :: Temp Table Sort Order

Apr 3, 2013

Is there a way to change the order that "select * from #table" returns data? It doesn't appear to return data in the same order that it was inserted into the table. This wasn't a problem with the same code in SQL Server 2005.

View 5 Replies View Related

Sort Data Table Smallest To Largest

Dec 30, 2014

i have table in sql and every month i am appending new data in this table, but i want to sort data Culumn Name "account_no' from smallest to largest, and whenever i append new data to this table it auto sort every time,

View 1 Replies View Related

Table Interactive Sort With Page Break

Dec 30, 2007

Hello
I have a table with a RowNumber Group which shows 10 rows in each page.
it works fine.
in the next step i put an Interactive sorting on one column.
i expect that the sorting is on the table no regarding the presentation which shows only 10 rows.
in reality what happens is that the table was sorted seperated for each part of the 10 rows table,
and no for the whole table.


does any one have a suggestion how to force the Interactive Sort , sorting he Whole table first
and only later to present 10 rows each page (use the group expression)

Thanks,

View 6 Replies View Related

How To Write A SQL Query To Sort A Table With The Priority Column As Well?

Jan 16, 2005

Hi,

Anyone can help me for the Sql query?

I want to sort a table with a priority column, e.g. in the following...

Table A
======
value
======
9
3
1
7
4
======

After sorting:

Table A
========
no value
========
1 1
2 3
3 4
4 7
5 9
========


Anyone can help me?
Thanks.

Daniel.

View 1 Replies View Related

Default Sort Order Of The Data When Inserting From One Table To Another

May 19, 2008



I have a data load process that reads data from flat file into a Stage table in sql server. The order of the records in the stage table is exactly same as the order in the flat file. The identity column on the Stage table (which is also the clustered index) represents the exact line/row number of the data in the filat file. I perform some transformations on the data in the stage table and then insert it into a cumulative table which has a clustered index on an identity column again. When I do this, does the order of the data in the cumulative table be in the same order as the data in the stage table? Anyone, please let me know if I can rely on SQL server to maintain the same order or I will be forcing a sort order on the Identity column (clustered index) of the stage table when I insert the data into a cumulative table.


Thanks in advance!!

View 3 Replies View Related

Making A (sort Of) Dynamic Pivot Table. I'm Stumped

May 11, 2008

Hello,

I've seem some good posts similair to this, but I haven't been able to find my exact issue.

I have the following table:







ID
Name
Location
Start
End

1
Joe
NY
2000
2001

1
Joe
CA
2002
2004

1
Joe
MA
2005
2008

2
Sue
NJ
2003
2004

2
Sue
FL
2004
2008

3
Bob
CA
1999
2000

3
Bob
WA
2001
2004

3
Bob
OR
2005
2006

3
Bob
MI
2007
2008


As you can see, the Location, Start and End dates can vary for each person and I don't know how many rows a single person might have.


The result I want, is a "pivot like" table.







ID
Name
Location1
Start1
End1
Location2
Start2
End2
Location3
Start3
End3
Location4
Start4
End4

1
Joe
NY
2000
2001
CA
2002
2004
MA
2005
2008




2
Sue
NJ
2003
2004
FL
2004
2008







3
Bob
CA
1999
2000
WA
2001
2004
OR
2005
2006
MI
2007
2008


I assume I can first do a count of the maximum rows for an individual and that is greatest number of columns I would need. But doing that and trying to figure out the rest has really stumped me.


Any thoughts, ideas and suggestions would be greatly appreciated.

Thank you.

-Gumbatman

View 11 Replies View Related

How To Sort Table In Sql2000 With Ipaddress(format X.x.x.x) As Column With Nvarchar Datatype In Ascending Order

Apr 19, 2006

How to sort table in sql2000 with ipaddress(format x.x.x.x) as column with nvarchar datatype in ascending order
without using stored procedure

Ex:

Table: netComputers(3 rows)
Column Name: ipAddress (string data type)

ipAddress
0.0.18.1
0.1.1.2
0.0.0.1

Sql query : if I use the query

Select ipAddress from netComputers order by cast( replace(ipaddress,'.','') as numeric(12)) asc

Gives result as :
ipAddress
0.0.0.1
0.1.1.2
0.0.18.1

Where as expected result should be:

ipAddress
0.0.0.1
0.0.18.1
0.1.1.2

View 18 Replies View Related

SQL Server 2012 :: Table Returning Function With Input Table Name As Parameter

Nov 19, 2014

I'm using SS 2012.

I started with an inline table returning function with a hard coded input table name. This works fine, but my boss wants me to generalize the function, to give it in input table parameter. That's where I'm running into problems.

In one forum, someone suggested that an input parameter for a table is possible in 2012, and the example I saw used "sysname" as the parameter type. It didn't like that. I tried "table" for the parameter type. It didn't like that.

The other suggestion was to use dynamic sql, which I assume means I can no longer use an inline function.

This means switching to the multi-line function, which I will if I have to, but those are more tedious.

Any syntax for using the inline function to accomplish this, or am I stuck with multi-line?

A simple example of what I'm trying to do is below:

Create FUNCTION [CSH388102].[fnTest]
(
-- Add the parameters for the function here
@Source_Tbl sysname
)
RETURNS TABLE
AS
RETURN
(
select @Source_Tbl.yr from @Source_Tbl
)

Error I get is:

Msg 1087, Level 16, State 1, Procedure fnTest, Line 12
Must declare the table variable "@Source_Tbl".

If I use "table" as the parameter type, it gives me:

Msg 156, Level 15, State 1, Procedure fnTest, Line 4
Incorrect syntax near the keyword 'table'.
Msg 137, Level 15, State 2, Procedure fnTest, Line 12
Must declare the scalar variable "@Source_Tbl".

The input table can have several thousand rows.

View 9 Replies View Related

T-SQL (SS2K8) :: Procedure That Create Views With Table Name And A Table Field Parameter?

Aug 4, 2015

I would like to create a procedure which create views by taking parameters the table name and a field value (@Dist).

However I still receive the must declare the scalar variable "@Dist" error message although I use .sp_executesql for executing the particularized query.

Below code.

ALTER Procedure [dbo].[sp_ViewCreate]
/* Input Parameters */
@TableName Varchar(20),
@Dist Varchar(20)
AS
Declare @SQLQuery AS NVarchar(4000)
Declare @ParamDefinition AS NVarchar(2000)

[code]....

View 9 Replies View Related

Sort Buttons Grayed Out In &"Data In Table&"

Aug 17, 2006

Hi -

This is a newbie question. For some reason when I view the contents of tables I have created on my SQL Server (version 7) database, the sort buttons in the "Data in Table" window are grayed out.

Do I need more permissions? How do I fix this?

Thanks.

View 1 Replies View Related

Default Sort Order - Open Table - Select Without Order By

Mar 27, 2008

Hi!

I recently run into a senario when a procedure quiered a table without a order by clause. Luckily it retrived data in the prefered order.

The table returns the data in the same order in SQL Manager "Open Table"

So I started to wonder what deterimins the sort order when there is no order by clause ?

I researched this for a bit but found no straight answers. My table has no PK, but an identiy column.

Peace.

/P

View 5 Replies View Related

Table As Parameter

Jan 11, 2008

Hello
I have aspx page and I need to insert 15 rows to a table so am thinking of passing them as table to  my sp
but I dont know how to use table as parameter in the sql2005 so PLs help me
 
thanks all

View 4 Replies View Related

Table Parameter In SQL 7

Jan 4, 2002

How do I pass a table name as a parameter to a stored procedure in SQL 7?

Thanks

View 1 Replies View Related







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