Handy Trick : Concatenate SQL Files
Aug 11, 2002
Hi all. Here is a little trick I came up with the other day. Although a bunch of yu may have already thought of it, I thought I might share it.
I had a directory with about 30 .sql files in it (each one a Create Procedure statement). I needed to deploy all the files to a live database. Being the incredibly lazy person I am I didn't want to open up each file and run it.
So, I dropped into DOS, went to that directory and typed
type *.sql > newfile.sql
This created a new file that contained all of the other files, I could just run that file in query analyzer and I was done.
Give it a try!
Damian
View 6 Replies
ADVERTISEMENT
Mar 4, 2008
Hi All,
I have a very simple question which I can't seem to find an easy way of doing in SSIS. (Alternatively I may be having a "Can't see the wood for the trees" moment )
I have a folder where files are deposited on a regular basis . (Every few seconds)
I want to take those files and concatenate them into a single file in another directory ready for processing.
The equivelent command prompt line would be copy c: estfiles*.* c: estfilescatteddata.dat
How would I be best doing this in SSIS? Also I could do with working out the best way to quiesce the folder so I don't get any locked files errors.
Any ideas?
Thanks
Nick
View 7 Replies
View Related
Sep 8, 2007
Hi people - need help with a little thing on SQL...
I have a function that returns a table of values where one row is called 'UserID' - lets call this table 'x'
I have a another table with a row called 'UserID' in it - lets call this table 'y'
I want an SQL statement that achieves:
Select everything from table x (the table that was generated by the function) where the UserID is not in any row of table y.
Anyone think they can help?
Regards,
Will
View 3 Replies
View Related
Feb 17, 2007
Hi all...I would like to know how it is possible to make my problem below all in ONEquery or stored procedure.I select some rows from a table where the resultset is one column with somevalues. Lets say 1, 4 and 7:row val1 12 43 7Then I would like these results to manipulate another table together withanother value (lets say some 'b' with value 5)Lets say the other table looks like this:id a b text1 1 1 'Some text'2 1 3 'Some text'3 1 5 'Some text'4 4 5 'Some text'5 7 4 'Some text'6 2 5 'Some text'in the above example the rows with id 3 and 4 match my criteria because 1and 4 (and not 7) was in the column 'a' together with the value 5 in column'b'.Here comes the tricky part (at least for me):Now because a row without the 'a' value 7 and the 'b' value 5 existed in thetable I would like to create one row with those values.Also because the 'b' column did have a the value 5 (the row with id 6)without any of the 'a' values of 1, 4 and 7 (here 'a' is 2), that row shallbe deleted.Then at last I would like the resultset matching 'a' column of 1, 4 and 7AND 'b' column 5 as a resultset.I hope that it is understandable and someone can help.- rick -
View 1 Replies
View Related
May 13, 2008
Hi everyone...
I have the following records...
Delivery_Table
ID Description PartNumber
1 one 123
Parts_Table
ID PartNumber Margin Unit_Price
1 123 2.3 0.0
2 123 0.0 63.69
If I join these two tables based on PartNumber, it returns me two records. What I want is that I want to select one record only (IF Margin > 0, than it should take the Margin Record, Otherwise, it should take Unit_Price Record)
For example,
ID Description PartNumber Margin Unit_Price
1 one 123 2.3 0.0
OR
ID Description PartNumber Margin Unit_Price
1 one 123 0.0 63.69
Any clues?
View 1 Replies
View Related
Jul 2, 2007
Hi, I have another question about code in RS.
I have a table cell with FORMAT of "$#,##0,0".
If I have any number in the cell I want to display it.
If I have 0 (zero) I want the cell to be empty.
I know how to do it with an expression:
iif (Fileds!myFiled.Value == 0,"", Fileds!myFiled.Value)
Now I want to do it with a code section:
=Code.hideIfZero(Fileds!myFiled.Value)
The problem is that the function should return Integer and if the value is zero I need to return empty string.
It does't say any thing about returning the string but when it trying to use the format on a string it give me a worning and print #ERORR in the cell.
is there a solution for this?
Do you know the syntax to format the number in the function before the return?
(Sorry for the dumb question but I know C# not VB.net and there is no intelisance in that editor).
Thanks a lot!
View 3 Replies
View Related
Mar 6, 2008
I have a table that looks like this:
RecordId
PictureId
KeywordId
111
212
313
421
522
623
725
817
932
1044
I need to run a query where I pass in an unknown number of KeywordIds that returns the PictureId. The 'IN' clause will not work because if a KeyWordId gets passed into the Stored Procudure the PictureId must have a record with each KeyWordId being passed in. For example, lets say you need to see the result of all PictureIds that have both 1 and 2, the correct result set should only be PictureId 1 and PictureId 2.
Im going crazy trying to find a simple solution for this. Please advise.
View 7 Replies
View Related
Apr 16, 2007
I have a custom folder layout for reporting services on our test environment so each tester can test the reports against the data in their own instances. The developers have reports in a different layout that's more in line with what will be in production. So I figured some simple RS scripting would handle things.
It was easy to create the folder structure, easy to create the shared data sources in each testers reports folders, and easy to deploy the report from the developers folder (source) to the testers report folders. However, when I try to use SetItemDataSources to change the data source in the newly duplicated reports, I keep getting an error telling me that the data source cannot be found.
Here's the relevant code fragment:
'Set report DataSource references
Dim DataSources(0) As DataSource
DataSources(0) = New DataSource
' update with new data source info
DataSources(0).Name = strDSName
Dim Item1 as DataSourceReference = New DataSourceReference
Item1.Reference = strRef
DataSources(0).Item = Item1
Console.WriteLine( "Setting report {0}, data source to {1}", strTargetReport, strRef)
RS.SetItemDataSources( strTargetReport, DataSources)
strDSName is "OLTP", strRef is the path to the shared data source, "/Reports/Tester1/Data Sources/OLTP". strTargetReport is the name of the report itself, full path name to "/Reports/Tester1/Report1".
Each tester has their own folder off the main reports folder "Reports", with an incremental number, as in "Tester1". Each testers folder has it's own Data Sources folder. There is only one data source for all reports, "OLTP".
/Reports
/Reports/Tester1
/Reports/Tester1/Data Sources
/Reports/Tester1/Data Sources/OLTP
/Reports/Tester1/Report1
/Reports/Tester1/Report2
I even went into SQL Server Management Studio and tried changing the (now broken) data source setting for a report to point to the correct data source (OLTP), then copied the generated script, then ran it - and still got the data source cannot be found error. That's what my latest code shown above was based on.
Anyone got any clues?
Thanks,
--Stan
View 3 Replies
View Related
Sep 25, 2007
I'm a bit stumped at this. I have done this before a bunch of times. The difference is that this time I have two rectangles in the footer. For the each, the visibility is set to an expression which checks whether the page is page 1 or 2. If it is 1, the first rectangle is visible, if 2, the second. When I reference the hidden fields on the main area of the report via ReportItems, they come through fine on the first rectangle, but are invisible on the second. I've tried the same exact fields and every time they are visible in rectangle1, and invisible in rectangle2. What is going on here???
View 2 Replies
View Related
Feb 1, 2007
Need help. How to concat into 1 row from the example below:
Table Address
Block Flr Road
2 1 Green
3 - Maine
4 3 Bell
5 2 Prade
Result :
Block 2 Flr 1 Green Road
Block 3 Maine Road
Block 4 Flr 3 Bell Road
Block 5 Flr 2 Prade Road
Cheers!
View 7 Replies
View Related
Aug 31, 2007
is it possible to concatenate 2 recordsets ? i have 2 select, and i need then to be displayed one after other.using union all the results are gathered, ordered like only one select.thanks for all
View 5 Replies
View Related
Oct 1, 2007
Hi, I am trying to write some simple SQL to join two fields within a table, the primary key is an int and the other field is a varchar. But i am receiving the error:'Conversion failed when converting the varchar value ',' to data type int.The SQL I am trying to use is:select game_no + ',' + team_name as matchfrom result Thanks
View 2 Replies
View Related
Feb 23, 2001
I'm trying to use a variable (@sqlfields1) for building a select statement.
Can someone please help me because the variable isn't set correctly when I'm trying to concatenate it with itself (the "@sqlfields1"-variable is declared as "char(50)":
If @showo1 = 1
select @sqlfields1 = 'o1,'
If @showo5 = 1
select @sqlfields1 = @sqlfields1 + 'o5'
I want @sqlfields1 to be = 'o1, o5'.
Regards,
Abrazame
View 2 Replies
View Related
Oct 25, 2004
Please help me with this if you can.
I have one table with CustomerID and some other data.
In other table i have CustomerID(the link with the first table) and Agent
The relation of the first with the second one is ONE TO MANY.
I want something like this:
Customer,'Agent1,Agent2,Agent3'
Is it possible.
Please help :)
View 3 Replies
View Related
Jul 27, 2007
Hey all
Just like the title asks...Is it possible...I have a table that stores memos but breaks the memo text field up and assigns a key to associate it all as one big text field in the application. What I am needing to do is to create a custom table for a customization to have the memo txt in one row per customer, per memo number. So, is there any way to concatenate memotext into one row per memo?
Thanks
tibor
View 14 Replies
View Related
Aug 31, 2007
is it possible to concatenate 2 recordsets ?
i have 2 selects and i want to display all results from the first
select and then the results from the second select query
with paging.
if i use union, all the results will be mixed.
thanks for the help!
View 7 Replies
View Related
Sep 29, 2012
Is there a way to concatenate the values of a particular field together into one field for all the records in each group of a GROUP BY without using XML?
Ideally, I want to accomplish this in a stored procedure. Normally, I would handle this in the front end, but my front end is Crystal ...
For example, if my data was:
1 "A"
1 "B"
1 "C"
2 "D"
2 "E"
I want to group by the first value and concatenate the second value:
1 "A,B,C"
2 "D,E"
Very easy using code - I simply add a function to the query in Access (not very efficient, but effective), or using recordsets in the app (which is actually very efficient) except my front end is Crystal in this case .
View 2 Replies
View Related
Mar 30, 2014
I have a table like so
code remarks
1234 abcd
4567 efgh
I need to concatenate the values in the remarks column into one row like below
abcd, efgh....how is it possible
View 4 Replies
View Related
Jan 25, 2007
I have a table like below.
certid name
1 xxx
1 yyy
1 cvb
now I want to output as xxx,yyy,cvb when i pass input certid=1
I want to get it using a single query statement
View 7 Replies
View Related
Mar 5, 2007
I hope this is the correct place to ask this...
I would like to concatenate a String value to an Int value using an SQL statement. At the moment it reads like this:
SELECT 'website.com/shop/product.cfm?ProductID=' + Products.ProductID AS Product_URL
But unfortunately I am getting the error:
"Conversion failed when converting the varchar value 'website.com/shop/product.cfm?ProductID=' to data type int."
Any idea how to get around this at all just using an SQL query statement?
View 2 Replies
View Related
Mar 27, 2007
-- Prepare sample data
DECLARE@Sample TABLE (ID INT, Code VARCHAR(3))
INSERT@Sample
SELECT290780, 'LT' UNION ALL
SELECT290780, 'AY' UNION ALL
SELECT290781, 'ILS' UNION ALL
SELECT290780, 'AY'
-- Show the expected output
SELECT DISTINCTs1.ID,
STUFF((SELECT DISTINCT TOP 100 PERCENT ',' + s2.CODE FROM @Sample AS s2 WHERE s2.ID = s1.ID ORDER BY ',' + s2.CODE FOR XML PATH('')), 1, 1, '') AS CODES
FROM@Sample AS s1
ORDER BYs1.ID
SELECT DISTINCTs1.ID,
STUFF((SELECT TOP 100 PERCENT ',' + s2.CODE FROM @Sample AS s2 WHERE s2.ID = s1.ID ORDER BY ',' + s2.CODE FOR XML PATH('')), 1, 1, '') AS CODES
FROM@Sample AS s1
ORDER BYs1.ID
SELECT DISTINCTs1.ID,
STUFF((SELECT ',' + s2.CODE FROM @Sample AS s2 WHERE s2.ID = s1.ID FOR XML PATH('')), 1, 1, '') AS CODES
FROM@Sample AS s1
ORDER BYs1.ID
Peter Larsson
Helsingborg, Sweden
View 20 Replies
View Related
Jul 23, 2005
I am beggining to learn stored procedures and I am trying toconcatenate the where clause below but I keep getting an error:declare @sqlwhere varchar(15)set @sqlwhere = 'parentid=2'select * from categories where @sqlwhereThis is the error I am gettingServer: Msg 170, Level 15, State 1, Line 3Line 3: Incorrect syntax near '@sqlwhere'.What am I doing wrong?ThanksRod
View 6 Replies
View Related
Jul 20, 2005
hi.Trying to concatenate two columns:select uname+' '+uaddress as NameAdr from tblUserI only get the first field, name!!??The datatype is both nvarchar. 100 and 50 chars long.If I run this query:select uname, uaddress from tblUsertheres no problem.Any suggestions?ThanksSWN
View 2 Replies
View Related
Oct 9, 2007
Hi there,
We are storing dates in a SQL table as dayPublished, monthPublished, yearPublished because sometimes not all the values are available.
I thought something like
select dbo.Resources.monthPublished + '/' + dbo.Resources.dayPublished + '/' + dbo.Resources.yearPublished as fullDate
but it doesn't like my slashes, and if I leave them out it simply adds the three fields together. Boo!
Any ideas?
Thanks,
Megan
View 3 Replies
View Related
May 2, 2008
Hi,
Whats wrong with the following T-SQL?
DECLARE @SQL NCHAR(4000)
SELECT @SQL = 'xxxx'
SELECT @SQL = @SQL + ' yyyy'
PRINT @SQL
I'm only seeing 'xxxx' in the debug window so it appears that its not adding the 2 strings?
Weird?!?
View 8 Replies
View Related
Jan 16, 2008
Hi,
I have a big problem, as I commented in other thread in this forum I Have a DataReader with an MDX query which right now runs out of memory, but I figured that if I made the query by range I could get what I need without running out of memory. However, to achieve that I need to concatenate at the end of a file with a Flat File destination, the result of every query, but I don't know how to do it, It always writes over the data.
View 8 Replies
View Related
Sep 20, 2007
Hi
I have a table similar to the following:
Date ID Name Job Number JobType
12/12/2007 123456 Fred Smith 111111 Full Day
12/12/2007 654321 Bob Blue 222222 Half Day AM
12/12/2007 654321 Bob Blue 333333 Half Day PM
I need the following output:
Date ID Name Job Number JobType
12/12/2007 123456 Fred Smith 111111 Full Day
12/12/2007 654321 Bob Blue 222222 Half Day AM
12/12/2007 654321 Bob Blue 333333 Half Day PM
Now before you say the output is the same . It isn't! There are only 2 records in the output. The italic lines are one record, with a carriage return linefeed between each piece of data. So for job number the field is equal to 111111 + CHAR(10) + CHAR(13) + 222222
Could someone please point me in the right direction?
Cheers
View 9 Replies
View Related
Feb 13, 2008
Is there any way of concatenating 2 fields and a seperator, an id (integer) then "|||" then a nvarchar field, it would make my life much easier if I could come up with SQL that works in ms access as well as sql server.. Thanks
View 7 Replies
View Related
Feb 20, 2008
Hi all I need some help in concatenatng a string in T-SQL. Having used the Command Microsoft Access inside the 'SQL View' window and typed the following it worked perfectly.
Code Snippet
UPDATE tblValidUsers SET blocked_users = blocked_users + 'name_123@hotmail.com;' WHERE userid='Onam'
However attempting the same command in T-SQL I get the following error:
Msg 403, Level 16, State 1, Line 1Invalid operator for data type. Operator equals add, type equals text.
Reason for having this command is I want to be able to add something to the end of the field "blocked_users" without actually overwriting the fields contents.
So for instance if I had the items: "Item1, Item2, Item3" in blocked_users and I updated it with "Item4" then the value "Item4" would be added to the end thus the use of "+" is used to concatenate. Is there a way of doing this in T-SQL?
Thanks for the help, Onam
View 6 Replies
View Related
May 13, 2015
I have the below problem:
DECLARE @t TABLE
(
ID int,
Name nvarchar(255)
)
INSERT INTO @t
SELECT 1, 'Raven'
[Code] ....
Returns the below:
ID Name
1 Raven
4 Raven
43 Jack
Any names which are appearing twice I would like to have only one row so concatenate the IDs into one row for each Name, like below:
ID Name
1, 4 Raven
43 Jack
Is this possible?
View 4 Replies
View Related
Oct 28, 2007
Hi everyone,
I'm writing a stored procedure where I need to concatenate two XML strings.
I would normally write XMLx = XMLy + XMLz
However because the variables are in XML SQL2005 doesn't like this and if I convert them to strings the XML structure gets lost.
Anyone any ideas ?
Thanks
D.
View 1 Replies
View Related
Mar 11, 2008
i have a table
View 1 Replies
View Related
Mar 19, 2008
I am creating a random-id in this way:
declare
@rand_id intset @rand_id=(SELECT ABS(CAST(CAST(NEWID() AS VARBINARY) AS INT)))
print @rand_id
now I want to add "-07" to the end of the random number generated.
if 12345 is the random number, i want it to be 1245-07.
Any idea how to concatenate the "07" to this random number?
View 4 Replies
View Related