Invalid Results For Order By On Select Query Against Table Variable
I am attempting to sort the results of a query executed against a table variable in descending order. The data is being inserted into the table variable as expected, however when I attempt to order the results in descending order, the results are incorrect. I have included the code as well as the result set.
DECLARE @tblCustomRange AS TABLE
(
RecordID INTEGER IDENTITY(1,1),
RangeMonth INTEGER,
RangeDay INTEGER
)
DECLARE @Month INTEGER
DECLARE @Day INTEGER
-- Initialize month and day variables.
SET @Month = 8
SET @Day = 11
-- Insert records into the table variable.
INSERT INTO @tblCustomRange
(RangeMonth, RangeDay) VALUES (1,2)
INSERT INTO @tblCustomRange
(RangeMonth, RangeDay) VALUES (1,27)
INSERT INTO @tblCustomRange
(RangeMonth, RangeDay) VALUES (6,10)
INSERT INTO @tblCustomRange
(RangeMonth, RangeDay) VALUES (9,22)
INSERT INTO @tblCustomRange
(RangeMonth, RangeDay) VALUES (12,16)
-- Select everything from the table variable ordering the results by month, day in
-- descending order
SELECT * FROM @tblCustomRange
WHERE (RangeMonth < @Month) OR
(RangeMonth = @Month AND RangeDay <= @Day)
ORDER BY RangeMonth, RangeDay DESC
I am getting the following resultset:
RecordID RangeMonth RangeDay
----------- ----------- -----------
2 1 27
1 1 2
3 6 10
I am expecting the following resultset:
RecordID RangeMonth RangeDay
----------- ----------- -----------
3 6 10
2 1 27
1 1 2
View Complete Forum Thread with Replies
Related Forum Messages:
Declaring A Table Variable Within A Select Table Joined To Other Select Tables In Query
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 Replies !
Specify Order For Select Results, Order By: Help!
Lets say I have a table named [Leadership] and I want to select the field 'leadershipName' from the [Leadership] Table. My query would look something like this: Select leadershipName From Leadership Now, I would like to order the results of this query... but I don't want to simply order them by ASC or DESC. Instead, I need to order them as follows: Executive Board Members, Delegates, Grievance Chairs, and Negotiators My question: Can this be done through MS SQL or do I need to add a field to my [Leadership] table named 'leadershipImportance' or something as an integer to denote the level of importance of the position so that I can order on that value ASC or DESC? Thanks, Zoop
View Replies !
Select Like And Order Results
Hello there, I have two tables I selecting name using like with %string% from the two tables but I need to order the result comes from the two table: 1- the exact match for the search string come first from the two table. 2- and the partial match comes last after the exact match. this is my DDL for the two tables : USE [Northwind] GO /****** Object: Table [dbo].[Person] Script Date: 04/25/2008 14:33:24 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Person]( [PersonID] [int] NULL, [Type] [char](10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [Name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [email] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF second table: USE [Northwind] GO /****** Object: Table [dbo].[Members] Script Date: 04/25/2008 14:33:52 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Members]( [MemberID] [int] NULL, [Type] [char](10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [Name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [Email] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF and this my search query I have it in a stored Proc. select * from ( SELECT PersonID, Type, Name, email FROM Person WHERE (Name LIKE '%'@Name'%') union all SELECT PersonID, Type, Name, email From Members WHERE (Name Like '%'@Name'%' ) ) Y Order by Case[Name] when @Name Then 1 Else 2 End, Case[Name] when 'm' Then 1 Else 2 End Thank you for your time Sms
View Replies !
Default Sort Order - Open Table - Select Without Order By
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 Replies !
Storing Results Of Select Statement In @variable
I'm new to sql stored procedures but I would like to store the results of an sql statement in a variable such as: SET @value = select max(price) from product but this does not work, can someone tell me how I would go about in storing the results in a variable. @value is declared as int Thanks in advance, Sharp_At_C
View Replies !
Select Query Results In Multiple Columns Based On &&"type&&" From Another Table
Using SQL Server 2005 Express: I'd like to know how to do a SELECT Query using the following tables: Miles Table: Date/Car/Miles/MilesTypeID =============== (some date)/Ford/20/1 (some date)Ford/20/2 (some date)Chevy/30/1 (some date)Toyota/50/3 (some date)Ford/30/3 Miles Type Table MilesTypeID/MilesType ================= 1/City 2/Highway 3/Off-Road I'd like the results to be like this: Date/Car/City Miles/Highway Miles/Off-Road Miles ===================================== (date)-Ford-20-0-0 (date)-Chevy-0-20-0 (date)-Ford-20-0-0 (date)-Toyota-0-0-50 (date)-Ford-0-0-30 Anyone? Thanks in advance!
View Replies !
Return The Results Of A Select Query In A Column Of Another Select Query.
Not sure if this is possible, but maybe. I have a table that contains a bunch of logs. I'm doing something like SELECT * FROM LOGS. The primary key in this table is LogID. I have another table that contains error messages. Each LogID could have multiple error messages associated with it. To get the error messages. When I perform my first select query listed above, I would like one of the columns to be populated with ALL the error messages for that particular LogID (SELECT * FROM ERRORS WHERE LogID = MyLogID). Any thoughts as to how I could accomplish such a daring feat?
View Replies !
How To Store The Results Of A Query In A Variable.
Can anyone tell me or point me in the direction of how I can store select query results to a variable in VB.NET? Im using the SqlDataSource control with dropdowns and textboxes for searching. I want to store the search results in a variable on the button click event.
View Replies !
Storing Query Results In A Variable
Can someone tell me how to store the results of a multi-row query in a text or varchar variable so that I might do something like this: declare @var1 text select @var1 = {results of select date, count(*) from testtable2 group by date) Thanks! joe
View Replies !
How To Assign Query Results Into A Variable
Hello, Could anyone help me please, I need a select to add the results into a variable of type string id(int) name (varchar2) 1 a 2 b,c 3 d,e,f,g tried wit the following: DECLARE @variable1 SELECT @variable1 = name FROM table The problem with this sentece is that the only value assigned to @variable1 is the last row value, i.e. @variable1 = "d,e,f,g" What I need is to concatenate all values returned by the query, i.e. @variable1 = "a,b,c,d,e,f,g" Thank you very much in advance, Marco
View Replies !
Assign A Variable Based Upon Query Results...how To Do It?
I have the following code which is incomplete. Where it says: txtVendorID = I need it to equal the results of the field VendorID from my query...here is my code. What do I need to add there? Dim cmdSelect As SqlCommandDim intRecordIDintRecordID = Request.QueryString("RecordID")strConn = ConfigurationManager.AppSettings("conn")conn = New SqlConnection(strConn)cmdSelect = New SqlCommand("spMfgRepListAddaspxByRecordID", conn)cmdSelect.CommandType = CommandType.StoredProcedurecmdSelect.Parameters.AddWithValue("@RecordID", intRecordID)conn.Open()cmdSelect.ExecuteReader()txtVendorID.Text = conn.Close()
View Replies !
'Invalid Object' When Select From Table I Own.
I have a database owned by the sa. In the database are some tables owned by id1. When I login via SQL Analyzer as id1 and try to select from the tables owned by id1, I get an error message 208 that the object does not exist. If I query 'select * from id1.table', I get my data. I thought that if I owned the table I could always access it. Additional facts, id1 is defined as a login, id1 is defined as a user for the database with db_owner role. Any ideas? Thanks, Jen
View Replies !
Select Query Based Upon Results Of Another Select Query??
Hi, not exactly too sure if this can be done but I have a need to run a query which will return a list of values from 1 column. Then I need to iterate this list to produce the resultset for return. This is implemented as a stored procedure declare @OwnerIdent varchar(7) set @OwnerIdent='A12345B' SELECT table1.val1 FROM table1 INNER JOIN table2 ON table1. Ident = table2.Ident WHERE table2.Ident = @OwnerIdent 'Now for each result of the above I need to run the below query SELECT Clients.Name , Clients.Address1 , Clients.BPhone, Clients.email FROM Clients INNER JOIN Growers ON Clients.ClientKey = Growers.ClientKey WHERE Growers.PIN = @newpin) '@newpin being the result from first query Any help appreciated
View Replies !
What All I Can Bind To My Select Query Results?
my question is what all can i bind my results of a select query to.i know we can use Dataset and Sqldatareader. can we use something else like hashtables. for example we can have:reader = cmd.ExecuteReader(); can we have something likeHashtable = cmd.ExecuteReader();
View Replies !
Assigning Results Of A Select Query To Variables...
Hi, I think I'm just braindead or simply thick...since this shouldn't be that hard, but I'm stumped right now. So, I'm trying to retrieve from a table, with a sql stored procedure with the sql like "select height, width, depth from products where id=@idinput" OK, so this part is easy, but if I wanted to say, return this to my code and assign height to a variable Ht, width to Wd and depth to Dp, how could I do that? This is what I've got so far... [code] cmdSelect = New SqlCommand( "GetProd", connstr ) cmdSelect.CommandType = CommandType.StoredProcedure dbcon.Open() dbcon.Close() [/code] The main prob is just what to connect this record to in order to access the individual fields. Thx :)
View Replies !
Select In Query Analyser... Results Truncated
Hello, In the query analyser, I execute a select ' restore database ' + name + ' from disk = " D:sql7dumpackup ' + name + '' + Name + ' _du_21.bak " with move ' ' + name + ' _Données " to " e:sqlbasesasesdata ' + name ' _données.mdf ", move ' ' + name + ' _Journal " to " d:sqllogs ' + name + ' _journal.ldf ", replace From sysdatabases And some lines are truncated in results ?. how to avoid that.
View Replies !
Displaying SELECT Query Results Conditionally...
Hello all, I have a problem... I have a SELECT query I have used in my PHP report. It is as follows: SELECT DISTINCT callref, CASE WHEN (stage.due_date < stage.completed_date) THEN 'SLA Breach' ELSE ' In SLA' END AS sla FROM tableX.... WHERE call_status=open..... I wish to search through all stages (i.e response, fix, end) of the calls logged in our database, & then return 'In SLA' for each call that had all its stages completed within the SLA, & 'Breach' for all calls that had even one of its stages completed outside its SLA. At the moment the SELECT query above gives me the following results: Call Ref sla 10001 In SLA 10002 Breach 10002 In SLA 10003 In SLA 10004 In SLA 10005 Breach 10005 In SLA ... ... What it should look like is this.... Call Ref sla 10001 In SLA 10002 Breach 10003 In SLA 10004 In SLA 10005 Breach ... ... Please let me know if anyone has the answers or any clues to this! thanks.
View Replies !
Send Results Of SELECT FOR XML Query To A File
I have posted this on previous forums, but the below code is a VB.net CLR stored proc that will accepts two parameters, a SELECT.... FOR XML query and a file path, and saves the resulting xml result into a file specified by the parameter. After compiling the VB code into a .dll than the T-SQL code to import the assembly, create the CLR proc and test it is included underneath. Hope some will find this useful Code Snippet 'Requires the Trial or Release version of Visual Studio .NET 2005 Professional (or greater). Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Data.SqlTypes Imports Microsoft.SqlServer.Server Imports System.Xml Partial Public Class outputxml <Microsoft.SqlServer.Server.SqlProcedure()> _ Public Shared Sub outputxml(ByVal XmlData As SqlXml, ByVal Filename As SqlString) 'Create the variables to hold the values that are supplied by the parameters 'input by the stored procedure Dim xmlDoc As New XmlDocument() Dim output As SqlPipe = SqlContext.Pipe() Try 'Load the result set into the XmlDoc Variable and then save the results in the 'path provided by the stored procedure. The values are provided by the 'input parameters of the stored procedure xmlDoc.LoadXml(XmlData.Value) xmlDoc.Save(Filename.Value) Catch ex As Exception 'If an error occurs catch the message and pipe it back to SQL output.Send(ex.Message.ToString) End Try End Sub End Class T-SQL CODE BEGINS HERE /*Alter the database to set trustworthy on in order to allow the ability to set the assembly to external access*/ ALTER DATABASE AdventureWorks SET trustworthy ON --Import the assembly into SQL CREATE ASSEMBLY outputxml from 'C:outputxml.dll' WITH PERMISSION_SET = EXTERNAL_ACCESS -- Create the proc from the imported dll CREATE PROCEDURE output @xmldata XML, @filename nvarchar(1024) AS EXTERNAL NAME outputxml.[outputxml.outputxml] .outputxml -- Test managed stored procedure DECLARE @output xml SET @output = (SELECT ProductID, Name, ListPrice FROM Production.Product Product FOR XML AUTO, ROOT('Catalog'), TYPE) EXEC dbo.outputxml @output, 'c:Output.xml' GO
View Replies !
How To Use ORDER BY Clause In An SELECT DISTINCT Sql Query When AS SINGLECOLUMN Is Defined?
Hi, I wonder if its possible to perform a ORDER BY clause in an SELECT DISTINCT sql query whereby the AS SINGLECOLUMN is used. At present I am recieving error: ORDER BY items must appear in the select list if SELECT DISTINCT is specified. My guess is that I cant perform the Order By clauses because it cant find the columns individually. It is essentail I get this to work somehow... Can anyone help? Thanks in advance Gemma
View Replies !
Spreading SELECT Query Results Over Multiple Pages
Hello.Lets say that there is a table with N rows. now, i want to display the table's data on a web page. one way is to select the whole table and add each row's data to the webpage (something like SELECT * FROM TABLE1).going this way will create a huge page. i want to speared the results over multiple pages - excatly as this forum spread each forum messages over multiple pages. for this purpose, i need to query Y rows each time, for example, if my table has 20 rows, and say that i want that each page will display 5 rows, then i need to query 5 rows each time. the first 5 rows for the first page, the next 5 rows for the second page and so on... is there any way to achieve it using an SQL query? the simplest way is to select the whole table and manaually filter the results. but this way will become slow as the table grows with data... and i dont want to select rows which i wont display anyway. any suggestions? Thanks.
View Replies !
How To Select Data From Excel Table By Original Column Order?
Hello, everyone: I have an Excel table that has columns like, Vendoe_Name Level Address Email Phone I use the statemen SELECT * FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0', 'Data Source=C: est.xls;Extended Properties=Excel 8.0')...[Sheet1$] and got output by column order, Address Email Level Phone Vendoe_Name How to make output by original column order like, Vendoe_Name Level Address Email Phone Any help will appreciated. Thanks ZYT
View Replies !
How Do I Use A Variable In A Select Query
How do i use a variable in a select query --------------- Declare @host varchar(20) set @host = '"Fab"' Declare @DB_name varchar(25) set @DB_name = 'config_mpl_18May2005' Declare @Full_Path varchar(60) set @Full_Path = @host + '.' + @DB_name + '.dbo.cfg_dn' Print '@Full_Path = ' + @Full_Path ------ cfg_dn ---------- Print 'Starting on CFG DN' select * from @Full_Path where dbid = 5441 or dbid = 5389 or dbid = 562 Error: Server: Msg 137, Level 15, State 2, Line 16 Must declare the variable '@Full_Path'.
View Replies !
Does It Store All The Results To Tempdb Database When I Query Against A Large Table Which Joins Another Table?
Hi, all experts here, I am wondering if tempdb stores all results tempararily whenever I query a large fact table with over 4 million records which joins another dimension table? Since each time when I run the query, the tempdb grows to nearly 1GB which nearly runs out all the space on my local system drive, as a result the performance totally down. Is there any way to fix this problem? Thanks a lot in advance and I am looking forward to hearing from you shortly for your kind advices. With best regards, Yours sincerely,
View Replies !
Variable For The Table Name In A SELECT Statement.
Hi,I'm trying to dynamically assign the table name for a SELECT statement but can't get it to work. Given below is my code: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE GetLastProjectNumber (@DeptCode varchar(20)) AS BEGIN TRANSACTION SET NOCOUNT ON DECLARE @ProjectNumber int SET @ProjectNumber = 'ProjectNumber' + REPLACE(CONVERT(char,@DeptCode),'.','') SELECT MAX(@ProjectNumber) FROM 'tbl_ProjectNumber' + REPLACE(CONVERT(char,@DeptCode),'.',''); END TRANSACTION Basically, I have a bunch of tables which were created dynamically using the code from this post and now I need to access the last row in a table that matches the supplied DeptCode. This is the error I get:Msg 102, Level 15, State 1, Procedure GetLastProjectNumber, Line 29Incorrect syntax near 'tbl_ProjectNumber'. Any help would be appreciated.Thanks.
View Replies !
Affecting SELECT Rows To A Table Variable
Hi, I would like to know how to add SELECT row to a table variable. It's not for my SELECT syntax(code following is just an ugly example) that I want help it's for the use of table variable. Your help will greatly appreciate!!! ex : DECLARE @MyTestVar table ( idTest int NOT NULL, anotherColumn int NOT NULL) SET @MyTestVar = (SELECT idTest, anotherColumn FROM tTest)-- This cause an error :-- Must declare the variable '@MyTestVar'. ???? What?
View Replies !
Getting Two Query Results Into 1 Table
SELECT PATNT_REFNO, PATNT_REFNO_NHS_IDENTIFIER, ARCHV_FLAG FROM dbo.S_PATIENTS WHERE (PATNT_REFNO_NHS_IDENTIFIER IS NOT NULL) SELECT dbo.S_PATIENT_IDS.END_DTTM, dbo.S_PATIENT_IDS.PITYP_REFNO, dbo.S_REFERENCE_VALUES.DESCRIPTION FROM dbo.S_PATIENT_IDS LEFT OUTER JOIN dbo.S_REFERENCE_VALUES ON dbo.S_PATIENT_IDS.PITYP_REFNO = dbo.S_REFERENCE_VALUES.RFVAL_REFNO WHERE (dbo.S_PATIENT_IDS.ARCHV_FLAG = 'N') i want to select the results from the querys into one table how would i do this ?
View Replies !
I Wanna Query A Purchase Order Table!...but Can Not:(
i use microaccess create table, there is a filed call"Complete_PO", value"yes/no" i wrote following statement to select it, but at runtime, there is warning message"...constraint...one or more row violating non-unique and so so..." how to solve it SqlSelectCommand2.CommandText = "SELECT Complete_PO FROM [PURCHASE ORDER] WHERE [PO_No] Like '%" & GetYearCode() & "%' ORDER BY Right(PO_No,4) desc" PoNum_SqlDataAdapter.Fill(PO_DataSet1) TextBox1.Text = PO_DataSet1.Tables("PURCHASE ORDER").Rows(0).Item("Complete_PO").ToString()
View Replies !
Create Table From Query Results
Hi everybody need help on the possibility creating a new table from the results of a view or query? below is my table named table1 ID col1 col2 1 a a 2 b d 3 c f this would be my new table named table2 ID col1 col2 col3 1 a a aa 2 b d bd 3 c f cf this new table has an additional column by concatenating col1+col2 tried this procedure but is not working CREATE TABLE AS (SELECT ID, COL1, COL2, COL1+COL2) TABLE2 thanks
View Replies !
Writing Query Results To New Table
I have written several scripts to pull in nested info to the analyzer window. How do I get this data to write to the new table I have created in the database? here is the current script: select Hierarchy_List.Hierarchy_Label as Hierarchy_Name, Hierarchy_List.hierarchy_ID as Hierarchy_ID, Hierarchy_List.Parent_ID as Parent_ID, frequency_item.manufacturer as Motor_Make, frequency_item.model as Frame from hierarchy_list full outer join Frequency_item ON HIERARCHY_LIST.HIERARCHY_ID = frequency_item.HIERARCHY_ID where parent_id in (select hierarchy_id from hierarchy_list where parent_id in (select hierarchy_id from hierarchy_list where parent_id in (select hierarchy_id from hierarchy_list where parent_id in (select hierarchy_id from hierarchy_list where parent_id=0) and parent_id<>0) and parent_id<>0) and parent_id<>0) and parent_id<>0 and frequency_item.description = 'motor' I need to move this data to the VAER.Al_Machines and the column names are the same. I can move data via DTS, but it won't work on this because the nested info. Is there a script addendum I can add to this to execute both the search and the transfer in one job so I can automate it? Thanks for any help. Mick Flanigan
View Replies !
Populating A Table With The Results Of A SQL Query
Is there any way i could take the first 50 results of a sql query and store them into 1 table in access and take the next 50 and store them into a second table in access? Is there any SQL statement that will direct where the output gets directed to? OR is there a way to have the sql reults paird up with a autonumbered ID? Doc
View Replies !
Displaying DMX Query Results In Table...
Hye Friends, I'm using a DMX query to get some predictions out of my MiningModel my DMX query is as follows : SELECT predict([x SalaryPredictor].[Emp Gross],20),predict([x SalaryPredictor].[Emp Basic],20) From [x SalaryPredictor] This query is returning me 2 objects of type expressions in my Dataset. The problem is when I try to drag these 2 fields in my Table i get a "#Error" value I executed the query in 'Data' tab and found that data is getting returned is a tree like format where "Expression" is at top & values expected ar its child nodes. I also found out that the returned objects are actually AdomdDataReader , but i'm not able to write a expression to get its values in my tables.... I want to display the values in the following format.... _____________________________ | Emp gross | Emp basic | --------------------------------------------------- | predicted val 1 | predicted val 2 | --------------------------------------------------- | .... | ..... | -- ------------------------------------------------- can anybody help me out in this ????... Thanks in advance !!!
View Replies !
How Do I Save My Query Results Into New Table
How do I save my query results into new table.... The ORIGINAL COLUMN Of course before parsing--- But the only data I want is in the three no name columns---(NO Column Name),(NO Column Name),(NO Column Name)I don’t want the original column saved back but I think it existing in the final query is blocking my Insert Into---
View Replies !
Random Selection From Table Variable In Subquery As A Column In Select Statement
Consider the below code: I am trying to find a way so that my select statement (which will actually be used to insert records) can randomly place values in the Source and Type columns that it selects from a list which in this case is records in a table variable. I dont really want to perform the insert inside a loop since the production version will work with millions of records. Anyone have any suggestions of how to change the subqueries that constitute these columns so that they are randomized? SET NOCOUNT ON Declare @RandomRecordCount as int, @Counter as int Select @RandomRecordCount = 1000 Declare @Type table (Name nvarchar(200) NOT NULL) Declare @Source table (Name nvarchar(200) NOT NULL) Declare @Users table (Name nvarchar(200) NOT NULL) Declare @NumericBase table (Number int not null) Set @Counter = 0 while @Counter < @RandomRecordCount begin Insert into @NumericBase(Number)Values(@Counter) set @Counter = @Counter + 1 end Insert into @Type(Name) Select 'Type: Buick' UNION ALL Select 'Type: Cadillac' UNION ALL Select 'Type: Chevrolet' UNION ALL Select 'Type: GMC' Insert into @Source(Name) Select 'Source: Japan' UNION ALL Select 'Source: China' UNION ALL Select 'Source: Spain' UNION ALL Select 'Source: India' UNION ALL Select 'Source: USA' Insert into @Users(Name) Select 'keith' UNION ALL Select 'kevin' UNION ALL Select 'chris' UNION ALL Select 'chad' UNION ALL Select 'brian' select 1 ProviderId, -- static value '' Identifier, '' ClassificationCode, (select TOP 1 Name from @Source order by newid()) Source, (select TOP 1 Name from @Type order by newid()) Type from @NumericBase SET NOCOUNT OFF
View Replies !
Save Prediction Query Results To A SQL Table
Can anyone show me how to run a prediction query and save the results to a sql table without using the T-SQL OPENQUERY tip here http://www.sqlserverdatamining.com/DMCommunity/TipsNTricks/3914.aspx? I am looking for an example in vb.net that I can use in a SSIS script task. Thanks
View Replies !
Group By Query Insert The Results Into Different Table
I am trying to do a select statement and input the result to a different table how can this be done in one step? Now I am just coping to excel and importing back in this is a real pain. Select Trip, Destination, LeaveDate, LeaveTime, ReturnDate, ReturnTime, Comment, RescheduleDate from Trips Group by Trip, Destination, LeaveDate, LeaveTime, ReturnDate, ReturnTime, Comment, RescheduleDate Order by LeaveDate, LeaveTime, Trip
View Replies !
|