Looping Through Query Result Column And PRINT To Log File....
May 24, 2007
i am creating a log file, and at 1 point I record how many rows are deleted after an update process.. I want to also record which productID are actually deleted... how would I write that?!
Basically I need know how I would get the list, and I am using PRINT command... I need to somehow write a loop that works through the list and PRINTS to the file....
Thanks in advance
View 1 Replies
ADVERTISEMENT
Jan 4, 2001
I've had a thousands instances where this technique would come in handy. Can somebody help me with a way to do a select, like a join parent and child table. Then say something like:
declare @variable varchar(30)
--some kind of loop through the result set
set @variable = queryfieldresult
if (@variable is not null)
begin
select * from table where productId = @variable
end
--end loop
Thanks,
Rick
View 1 Replies
View Related
Feb 13, 2001
HI,
I ran a select * from customers where state ='va', this is the result...
(29 row(s) affected)
The following file has been saved successfully:
C:outputcustomers.rpt 10826 bytes
I choose Query select to a file
then when I tried to open the customer.rpt from the c drive I got this error message. I am not sure why this happend
invalid TLV record
Thanks for your help
Ali
View 1 Replies
View Related
Mar 28, 2008
Im having a issue. Im not sure how I am going to carry out but I have two tables in SQL server 2005
TABLES
Category SubCategory (PK)CategoryName (PK) SubCategoryNameCategoryID SubCategoryIDDate Date (Just shows the date inserted) (FK)CategoryID
On the front page, I need to have it querys out the CategoryName from Categorys but also querys out all....Well not all but atleast 5 subcategorys that relate to that categoryName. Once its down it moves to the next category and does the same and so on. Does anyone know the trick ?
View 5 Replies
View Related
Feb 25, 2012
When I run query in excel it gives result with different column sequence. The same query gives result with different column sequence when used in query analyzer or VBA Macro. E.g., Select * from ABC.
result in Excel 2003 SQL OLE DB query
col-A col-B col-C
values...
Result with Query Analyzer and VBA Macro
col-c col-B col-A
values...
View 3 Replies
View Related
May 9, 2015
I have a column colC in a table myTable that has a value (e.g. '0X'). The position of a non-zero character in column colC refers to the ordinal position of another column in the table myTable (in the aforementioned example, colB).
To get a column name (i.e., colA or colB) from table myTable, I can join ("ON cte.pos = cn.ORDINAL_POSITION") to INFORMATION_SCHEMA.COLUMNS for that table catalog, schema and name. But I want to show the value of what is in that column (e.g., 'ABC'), not just the name. Hoping for:
COLUMN_NAME Value
----------- -----
colB 123
colA XYZ
I've tried dynamic SQL to no success, probably not executing the concept correctly...
Below is what I have:
CREATE TABLE myTable (colA VARCHAR(3), colB VARCHAR(3), colC VARCHAR(3))
INSERT INTO myTable (colA, colB, colC) VALUES ('ABC', '123', '0X')
INSERT INTO myTable (colA, colB, colC) VALUES ('XYZ', '789', 'X0')
;WITH cte AS
(
SELECT CAST(PATINDEX('%[^0]%', colC) AS SMALLINT) pos, STUFF(colC, 1, PATINDEX('%[^0]%', colC), '') colC
[Code] ....
View 4 Replies
View Related
Jan 11, 2005
Simple example would look like that in MS SQL
SELECT 'a' AS (SELECT language_name FROM language WHERE language_id = 1)
So that the display is
English
a
as we assume that
SELECT language_name FROM language WHERE language_id = 1
returns only English
I have tried to that with a variable but it does not work
declare @that as varchar(15);
set @that = (select language_name_u from language where language_id = 1);
select 'a' as @that
LOL
I just tried another way as i was going to post
declare @that as varchar(15);
set @that = (select language_name_u from language where language_id = 1);
select 'a' as "@that"
and it worked!
Posting anyway so people might answer with a better solution with no variable
Thanks a lot
Mordan
View 1 Replies
View Related
Nov 5, 2003
I am using MSDE and WebMatrix. My stored procedure is creating a Dynamic SQL query and is is about 200 lines long.
I am not getting the expected results, but also not generating any errors. I inserted a Print statement to print the resultant SQL query, but I don't know how to see or display that print result.
I do NOT have SQL2000, only MSDE. I am using WebMatrix and VB.net to create my application. Is there some class in asp.net that will help me, or some free utility. One of the problems is that the dynamic SQL is using over 20 parameters to create the query; the end result of the user picking fields on the webform.
View 7 Replies
View Related
Jul 20, 2005
I am firing a query like:SELECT TaskName, StartDate FROMTasksWHERE StartDate >= '01-Aug-2003'Now the result comes as:TaskName StartDate--------------------------Task1 01-Aug-2003Task5 10-Oct-2003etc.Now what I want is this:Sl. No. TaskName StartDate----------------------------------1 Task1 01-Aug-20032 Task5 10-Oct-2003How do I get the Sl. No. field (it does not exist in the table).Can I do it?-surajit
View 11 Replies
View Related
Nov 23, 2007
Hi,
I'm wondering is it possible to store query result to column directly?
for example I have 2 tables
Cache
----------
Cache_ID (int)
Cache_content (Text)
cache_created (Datetime)
Orders
-------------
Order_ID
Order_amount
Order_Date
Order_Delivered
and the query is
select * from order where order_date = '2007-11-23' and 'Order_delivered='N'
I want the result to be stored in cache table either csv or xml
I'm using sql 2000 server.
any idea?
View 7 Replies
View Related
Jun 3, 2004
I'm having a bit of a trouble explaining what I'm trying to do here.
I have 3 "source" tables and a "connecting" table that I'm going to use
tblContacts - with contactID, ContactName etc
tblGroups - with GroupID, GroupName
tblSubGroups - with SubGroupID, GroupID and SubGroupName (groupID is the ID for the parent Group from tblGroups)
They are related in a table called
tblContactsGroupConnection - with ContactID, GroupID and SubGroupID
One contact can be related to many subgroups.
What I want is a list of all contacts, with their IDs, names and what groups they are related to:
ContactID, ContactName, [SubGroupName1, SubGroupName2, SubGroupName3]
ContactID, ContactName, [SubGroupName1, SubGroupName3]
ContactID, ContactName, [SubGroupName3]
I'm sure there's a simple solution to this, but I can't find it. Any help appreciated. :)
Kirikiri
View 1 Replies
View Related
Jul 27, 2015
I have the below query which gives me statement to apply the login name, SID and PWD and that I statement I can apply to Dr and secondary server. Incase of failover there will be no connection issue.My query is
SET NOCOUNT ON
SELECT 'EXEC sp_addlogin @loginame = ''' + loginname + ''''
,', @defdb = ''' + dbname + ''''
,', @deflanguage = ''' + language + ''''
[code]....
This query output I wanted in a sqlfile so that I can schedule a batch file or sqlcmd and apply the login detail from the new one inserted in the primary.
View 3 Replies
View Related
Dec 10, 2007
We can save query output save as CSV file directly from the Query Analyzer window. I have done it at last few year before. Now I need it.Can anyone please give the one example for the same.
Thanks
Amit K Patel
View 7 Replies
View Related
Apr 21, 2005
Hello Friends
My problem is
Suppose Query is - Select * from tbl_Employee
TBL_EMPLOYEE HAS ONLY TWO COLUMNS NAME,POST
I need that an extra column get inserted in result through query showing serial Number with each row.So that query result look like this.
Serial Name Post
1 XYZ QER
2 SDF OPO
3 WER IPO
If any body knows please post the solution its urgent.
View 11 Replies
View Related
Apr 23, 2004
I have a query that returns a list of results from the database and insert the results into a datatable. Is there any way to add a column to the query result that has autonumbers in it. for example the first record would have 1 the next 2, the next 3, and so on?
View 4 Replies
View Related
Aug 29, 2007
Hi,
I want to export/output result of a query to a CSV file using SQL Server 2005. How can i do it ? I just want to do it all using SQL Server 2005 query window without having to use some 3rd Party control or software. Is it possible and how? Is there some SP which can convert the result to a CSV File ?
Thanking you...
View 4 Replies
View Related
Jan 24, 2001
Hi All
I am using cursor in my SP, according to my condition I might be getting around 600 records all this records to send to text file, I have tried few option some how I am able to create file and I am geeting only the last record in my output file, I want to know how can I append records into output file(text file), If some one can give me some suggestion that will be great.
Thanks in advance
Regards
Ram
View 1 Replies
View Related
Sep 4, 2006
Hi Gurus,
Can u help me out in the following two scenario/problems.
1. I want to save the query results (which is generated within execute sql task) to file (which does not exists & should be created at run time). is it possible?
2. Can I define the file name, in Flat File connection Manager, dynamically (by using some variable)?
Your support and help will be appreciated...
regards,
Anas
View 8 Replies
View Related
Sep 18, 2007
Hi,
I need to create a derived column for each row in a SQL dataset.
This derived column needs to be created by passing across two values from the SQL dataset and querying an Oracle table based on those parameters. If the Oracle query returns a record(s) then the derived column should be set to 1 otherwise leave it as default (0).
One of these parameters needs to check a date range so I can't use a Lookup Transformation...any ideas how I can accomplish this ?
Thanks
View 5 Replies
View Related
Aug 17, 2001
In SQL7 Query Analyzer we want the results of a SELECT statement not to be displayed on screen but written to a text file.
We assume that in the tons of sp_ and SET statements there should exist
one where output file can be defined.
Greetings from Mannheim, Germany
Ricardo
View 1 Replies
View Related
Jan 3, 2008
i want to save the result of the query to a xml file .when any dml operations done on the table then the whole table must be appeared in the xml format in xml file.("Select * from Table_name").
Can any one help me out.
this must be dont directly .not by using any of the tools.
Suppose in sqlserver express we can do this by using 'bcp' tool.But i dont want that .Plzz Help me out.
Thanks & Regards ,
Anujahnavi S.
anujahanvi
View 1 Replies
View Related
May 9, 2007
Hi,I need to output result of my query to txt file. So I'm using -oparameter, for example:osql.exe -s (local) -d database1 -U sa -P sa -i 'c:\queryFile.sql' -o'c:\output.txt'But it clears existing output.txt file first and then outputs theresult, while I need to append the result of my query without clearingexisting file content. Is it possible ?
View 1 Replies
View Related
Sep 9, 2015
Code snippet that will Execute sql select query and automatically import the results to csv files.
View 6 Replies
View Related
Mar 20, 2015
I have a query which provides the below result set:
1165 6
1,173.0013
9740 6
9820 13
2271 6
2287 13
10,952.006
11,029.0013
4,074.006
4,103.0013
I want to achieve something like below. It should subtract the '13' row to '6' row and provide another column with the result. the '6' and '13' category code share the same Key.
1165 6 -8.00
1,173.0013-8.00
9740 6 -80
9820 13 -80
[code]...
View 5 Replies
View Related
Jan 23, 2008
hi
i am using sql server 2000.
1. can i save the sql result to an ascii file using tsql commands. i don't want to use the menu option.
2. how can i use parameters in query statements. pls give me some exampls
3.is there any way to get the row numbers along with the query results
thanks & regards
Sam
View 7 Replies
View Related
Apr 22, 2008
Hi Everyone,
I am looking for a few pointers on how to achieve something. For the purpose
of my application I need to specify a SQL Server table. After this I wish to
be able to loop through column types and calculate the appropriate .NET
datatype based on the SQL Data Type, and also figure out if the column
allows NULL values.
I'm not looking for someone to do my work for me, just some pointers on what
I should be reading to achieve my aim.
Kind Regards
View 2 Replies
View Related
Apr 5, 2014
Here are two tables:
TABLE_A
[ac] [dest]
1 A
1
1
2
2
3
3 B
3
(ac=1, dest=A; ac=3, dest=B)
The space between '1' and 'A' isn't showing up correctly.
TABLE_B
[fleet] [ron]
1 A
1 A
1 A
1 A
1 A
2
2
2
2
3 B
3 B
(fleet=1, ron=A; fleet=3, ron=B; etc.etc.)
I would like to fill TABLE_B's column "ron" by referring to TABLE_A's column "dest".ac = fleet, and for each ac, I would like to loop through the 'dest' column in TABLE_A from top to bottom to get the top most value. If there are no values (like with ac = 2), then value is blank.
For 1, the value is A.
For 2, the value is blank.
For 3, the value is B.
Therefore, in TABLE_B, for all 'ron' for fleet=1, the value is filled A.
For all 'ron' for fleet=2, the value is blank.
For all 'ron' for fleet=3, the value is B.
- create variable 'v'
- where ac=fleet, loop through 'dest' from top to bottom to get top-most value. variable 'v' = the value.
- in TABLE_B, for each ac=fleet, insert variable 'v' into the 'ron' column
View 1 Replies
View Related
Sep 4, 2007
Hi,
Hopefully someone can assist me with what appears to be a simple issue - and hopefully I am just looking in the wrong location - because I am almost going nuts trying to work this out!!
I am wanting to pickup a file from a given folder, do some transformations on the data within the file, and then dump each row within the original file as a seperate txt file into a new folder.
I have managed to get it working - well all except having each row as a seperate txt file. Currently all the rows are outputed into the same txt file. argh
As it stands I have a For Each Loop Container, within this i have a Data Flow Container; which in itself, just has the source, some derived columns, and then an output.
How can I get this to pull each row from the source and put it as a seperate txt file. If someone can just nudge me in the right direction it would be much appreciated.
Thanks in advance
Troy
View 5 Replies
View Related
Mar 20, 2008
I have table like below
ID AMT
1001 1234.560
1001 34.560
1001 134.000
1002 45.000
1002 3456.000
1003 5678.999
I need to create a fixed length data file..For example, ID char(6) and amt num(10.3) and sum(23.3)
It should be group and order by ID : 01 Represent ID line and 02 represent amt ( there can be multiple amt records) and 03 represent sum of amt.
01 + ID
02 + AMT
03 + Sum(AMT)
The output should look like this.. How do this either using a t-sql or SSIS?
011001
021234.560
0234.560
02134.00
031403.12
011002
0245.000
023456.000
033501.000
011003
025678.999
035678.999
View 6 Replies
View Related
Oct 22, 2014
I'm converting a terribly written ColdFusion script and migrating it to T-SQL (SQL Server 2012). My problem is, I'm having issues with how to get these loops sorted out. For instaces, the CF query wouold be something like :
<cfquery name = "getData" datasource = "db">
SELECT id, name, date FROM table
</cfquery>
Following that, this query is looped into another set of queries:
<cfloop query = "getData">
<cfquery name = "getAddress" datasource = "globaladdress">
select * from globalAddress
where addressID = '#addressID#'
</cfquery>
[code]...
What I'm looking to do is turn the first query "getData" into the above loop, but rather in T-SQL.
View 4 Replies
View Related
May 1, 2008
As the topic suggests I need the end results to show a list of shows and their dates ordered by date DESC.
Tables I have are structured as follows:
SHOWS
showID
showTitle
SHOWACCESS
showID
remoteID
VIDEOS
videoDate
showID
SQL is as follows:
SELECT shows.showID AS showID, shows.showTitle AS showTitle,
(SELECT MAX(videos.videoFilmDate) AS vidDate FROM videos WHERE videos.showID = shows.showID)
FROM shows, showAccess
WHERE shows.showID = showAccess.showID
AND showAccess.remoteID=21
ORDER BY vidDate DESC;
I had it ordering by showTitle and it worked fine, but I need it to order by vidDate.
Can anyone shed some light on where I am going wrong?
thanks
View 3 Replies
View Related
Aug 16, 2005
I am not sure if what I wish to do is possible, but I shall ask anyway;
My project examines a database log of all the pages of an online teaching tool. Once the user has completed all the pages they are to be issued a certificate. Users may complete the teaching tool in any order, and the pages are always stored whenever they are acccessed, regardless of certification.
I have created a number of views that extract the data into a list of all the possible completion dates; i.e. where all the pages have been completed within any 12 month period. I need to write a query/view that uses the view to extract the first possible user completion date followed by every completion 12 months after that, then after that etc. to present day.
Can I do this?
Am I making sense ?
A no is acceptable in this case; I know I can do this with multiple queries from withing an application. I'd just rather not.
View 4 Replies
View Related
Apr 9, 2008
This is the TABLE I have
IDBRANCH STATUS
1A ACTIVE
1BINACTIVE
1CINACTIVE
2BINACTIVE
2CINACTIVE
2DINACTIVE
3A ACTIVE
3B ACTIVE
3C ACTIVE
4B ACTIVE
5DINACTIVE
----------------------------------------------------------------
Following is the desired View that I need for the above table.
Any ID which has atleast one ACTIVE branch will have ACTIVE status and any company which have all of its branches INACTIVE will have INACTIVE status. Thanks for your help
IDSTATUS
1 ACTIVE
2INACTIVE
3 ACTIVE
4 ACTIVE
5INACTIVE
View 2 Replies
View Related