Concatenating Filename And Variable/string
Mar 31, 2008
I'm trying to write a stored procedure in SQL that will make a copy of a file and then append the current date to the end of the copy's filename. I'm storing the date in a variable called @currentdate which is defined as:
declare
@currentdate varchar(10)
set @currentdate='' + 'select datepart(month,getdate())' + '-' + 'select datepart(day,getdate())' + '-' + 'select datepart(year,getdate())'
Here is the SQL code I'm using:
exec xp_cmdshell 'copy "C:DevelopmentParticipant Limits ReportParticipant Limits Report template.xls" "C:DevelopmentParticipant Limits ReportParticipant Limits Report ' + @currentdate + '.xls"'
GO
The resulting file should have a filename something like "Participant Limits Report 3-31-2008". I get an "Incorrect syntax near '+'." error.
View 20 Replies
ADVERTISEMENT
Aug 13, 2003
Hi All,
I am trying to write a select statement which will concatenate all values of a string column and provide me with a result set containing just one row of data containing a concatenation of all values.
For eg:
column1
abc
def
hij
klm
nop
is it possible to write a select statement which would return
result
abcdefghijklmnop
as a result?
TIA
Ketan
View 6 Replies
View Related
Mar 12, 2008
Hey guys, I 'm coding my very first stored procedure as accessed by a
.NET application. My input parameter is a dynamically built string. I need to concatenate to a sql query within the SP. I've tried using '+' as the concat. character but it doesn't work.
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER procedure [dbo].[tmptable_query] (@condition_cl varchar(100)) as select * from temp_table + @condition_cl
Help would be appreciated. Thank you.
View 5 Replies
View Related
Jul 20, 2005
I am trying to create a job that, as one of its steps, will kick off aDTS package. As part of the command parameter, I need to concat asystem variable (@@SERVERNAME) to a constant string. I am receiving anerror about incorrect syntax near the +.Here is the code for the job step.-- Add the job stepsEXECUTE @ReturnCode = msdb.dbo.sp_add_jobstep@job_id = @JobID,@step_id = 1,@step_name = N'Import OCC Series Data',@command = N'DTSRun /FD:DatabasesScriptsDTSImportOCCSeriesData.dts /A DbName:8=' +@@SERVERNAME,@database_name = N'',@server = N'',@database_user_name = N'',@subsystem = N'CmdExec',@cmdexec_success_code = 0,@flags = 2,@retry_attempts = 0,@retry_interval = 1,@output_file_name = N'',@on_success_step_id = 0,@on_success_action = 3,@on_fail_step_id = 0,@on_fail_action = 3IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollbackIf I just try SELECT N'DTSRun /FD:DatabasesScriptsDTSImportOCCSeriesData.dts /A DbName:8=' +@@SERVERNAME, everything works fine. I even tried declaring a localvariable named @command and setting it in the select statement, but nodice.
View 2 Replies
View Related
Oct 10, 2001
Does anyone know how to execute a directory listing of a file and return the file name to a variable in SQL? For instance, there's a file called c:datach20011010.txt and i execute the following:
xp_cmdshell 'dir c:datach*.txt'
or any other transact sql or procedure, how can i get the filename into a variable...all in sql?
FYI - I need to pass a filename to a process so that it can bcp the data into a temp table. But I don't know the filename at the time the process is setup/scheduled.
TIA,
Mike Nolen
View 3 Replies
View Related
Mar 27, 2015
Each patient has multiple diagnoses. Is it possible to concatinate all of them in one without using a cursor?
I attach a small sample - just 3 patient (identified by VisitGUID) with the list on the left, the desired result on the right.
View 8 Replies
View Related
Jan 14, 2008
I'm trying to read the filename from a file that I'm downloading by FTP (FTP Component) into a string variable so I can later use it for another part of the process, how can I do this?
View 2 Replies
View Related
Jul 20, 2005
Hi.I am trying to create a database based on variables from xp_regread.Somehow I can´t pass @dBDir as FILENAME.I get the following error-message :Server: Msg 170, Level 15, State 1, Line 24Line 24: Incorrect syntax near '@dBDir'.What am I doing wrong ?I think the problem is somehow related to a datatype-problem orit is simply not possible to pass a variable to a "createdatabase"-statement.I have checked the xp_regread-output...naturally :) ...and it is correct.Hope someone can help :)regardsMichael----------------------------------------Source-code is as follows:USE masterGODECLARE @dBDir nvarchar(128)DECLARE @dBlog nvarchar(128)EXECUTE xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARESchool-ProjectIRPFDatabase','dBDir',@param = @dBDir OUTPUTSET @dBDir =@dBDir+'IRPF.mdf'SET @dBlog =@dBDir+'IRPF.ldf'CREATE DATABASE IRPFON PRIMARY( NAME = IRPF_db,FILENAME = @dBDir)LOG ON( NAME = 'IRPF_log',FILENAME = @dBlog)GO
View 2 Replies
View Related
Sep 15, 2006
I want have multiple records from 1-4500 that I must insert a picture into the database for. I am trying to set up a variable to do this if someone can show me my error I would apprieciate it. This table has 4 columns (id# Float is a FK) (ImageName nvarchar (10)) (ImageFile Varbinary(Max)) (rec# int PK Increment Seed).
declare @jpg as int
Set @jpg = 0
While @jpg <4500
begin
set @jpg = (@jpg + 1)
use consumer
insert photo (id#, ImageName, ImageFile)
Select @jpg, '@jpg.jpg',
bulkcolumn from Openrowset (Bulk 'D:DataPics@jpg.jpg', Single_Blob) as 'ImageFile'
View 6 Replies
View Related
Apr 5, 2006
I have a customer who has recently migrated their SQL server to a newserver. In doing so, a portion of a stored procedure has stoppedworking. The code snippet is below:declare @Prefixes varchar(8000),declare @StationID int-- ...select @Prefixes = ''select @Prefixes = @Prefixes + Prefix + '|||'from Devicewhere Station_ID = @StationIDEssentially, we are trying to triple-pipe delimit all the deviceprefixes located at a specified station. This code has workedflawlessly for the last 10 months, but when the database was restoredon the new server, @Prefixes only contains the prefix for the lastdevice.Is there a server, database, or connection option that permits this towork that I am not aware of? Why would this work on the old server andnot on the new? (BTW - both servers are running SQL 2000 StandardSP4).Thanks!
View 6 Replies
View Related
Sep 20, 2007
Hello,
I apologise if this question has been asked before but I have searched forums and the web and have not found a solution. I am current creating a script that has a cursor that builds a sql statement to be executed e.g.
--code within cursor
SELECT '
DECLARE @Result INT
EXEC @Result = DELETE_DOCUMENT
@DocumentID = ' + STR(DocumentID) + ',
@TimeStamp =' + CAST([Timestamp] as varchar) + ',
-- CHECK RESULT AND STATUS
-- IF OK LOG IN META_BATCH ELSE LOG ERROR' AS SQL
FROM Document
The problem I am having is trying to join the timestamp column into the sql string. I have tried to cast the time stamp to a varchar but I end up with the following output for the timestamp column values
T
T€‘
T
xnĂž
T!
T"
T#
T$
T%
T&
T'
T(
T)
T*
T+
T,
instead of
0x0000000013540F1C
0x0000000013540F1E
0x0000000013540F1F
0x0000000013786EDE
0x0000000013540F21
0x0000000013540F22
0x0000000013540F23
0x0000000013540F24
0x0000000013540F25
0x0000000013540F26
0x0000000013540F27
0x0000000013540F28
0x0000000013540F29
0x0000000013540F2A
0x0000000013540F2B
0x0000000013540F2C
which would not allow my delete script to work correctly. So I would really appreciate some advice to a pointer to where I might find out how to convert the timestamp.
Thanks
Sam
View 3 Replies
View Related
Sep 7, 2007
Hope I can make this clear...
I have to download a file via FTP from one of our vendors, the filename is MMDDYYYY.zip, this is a weekly file and is posted between Tuesday and Thursday, so basically I never know exactly what the file is going to be called, to fix that, I added a FTP Task that will download a file if the date = today (Today = Thursday, when the job kicks off), if this fails, try a file where the name = today-1 (Wednesday), if this fails, try today-2 (Tuesday), all of that inside of a Sequence Container and with MaximumErrorCount set to 3. This is fine and it works fine, good.
Now my other issue, the .txt file inside the zip file (1080.txt), after being decompressed, needs to be renamed to MMDDYYYY.txt, where MMDDYYY = to the file I downloaded, but I never know what the file is going to named (MMDDYYYY, MMDD-1YYYY, MMDD-2YYYY).
Is it possible to output the filename of the file that I successfully download to a variable, so I can re-use name?
Any other thoughts?
View 1 Replies
View Related
Jun 20, 2007
Why does the raw file have an option for a variable path and the flat file destination does not? Not having this feature makes it impossible to work with variable environments. Please add this option to the Flatfile Destination.
View 5 Replies
View Related
Mar 31, 2008
Hi All,
may be i'm asking a question that was discussed for billion time, but i can't find exact answer.
So i have access database that generates .xml or xls files by pressing button. So user select from drop down menu id ( e.g. 100,101,102,103 etc) and then file 101.xml or 102.xml or 101.xls or 102.xls is generating.
i need SSIS package to be configured to get filename is variable and then use insert data from xml or xls file to the related table
I don't understand how to pass file name through variable to SSIS package and then work with so called "variable".xls or
"variable".xml file. Could you please give detailed answers if it's possible?
Your early reply will be very much appreciated
Thank you
View 10 Replies
View Related
Aug 13, 2007
Is there a way to configure the XML source component to use a schema file whose filename is in a variable? Now I know it doesn't make any sense to have an XML source whose schema can vary, however, I have a parent package with a ton of child packages, all of which process the same XML input using the same schema. What I would like to do is for the parent to load the filename of the XML input file into a variable, and the filename of the XML schema file into another. Each child would have its XML source configured to pickup these variables from the parent, so that if the location or name of the schema changes, I don't have to edit each package one-by-one. However, it doesn't seem possible to specify anything but a filename for the schema. Any suggestions?
View 5 Replies
View Related
Feb 27, 2008
Hi, I want to get my SSIS package to look for a file in a named directory that has a ceratin string in the filename.
example - My file is in a folder called data and the filename is 'System_UT_INCR_BOOKINGHEADER_20080214000000.TXT' Every day the fiel name changes to reflect the current date. I need my package to search for the String "BOOKINGHEADER". I know I need to create a variable with that value but I am not sure (using the example below) how to write the code to do this.
Imports System.IO
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Public Class ScriptMain
Public Sub Main()
Try
File.Move(Dts.Variables("Source").Value.ToString, Dts.Variables("Destination").Value.ToString)
Dts.Events.FireInformation(0, "", "File Moved Succesfully", "", 0, True)
Catch ex As Exception
Dts.Events.FireError(1, "", "Source file or destinations does not exist", "", 0)
End Try
Dts.TaskResult = Dts.Results.Success
End Sub
End Class
View 3 Replies
View Related
Aug 10, 2006
I am wanting to capture the file name I am using to load data from and use it in a SQL statement to insert it along with the data that I load.
I am using a ForEach container to load all my .txt files but cannot figure out how to capture the name of each source file as it loops through the files and then add it to my insert statement that is populating my history table. I would think that the ForEach container has that information, but I do not see how to access it and assign it to a variable that I could use in my SQL statement.
Any ideas or suggestions?
View 4 Replies
View Related
May 2, 2007
I want to create a SP that creates a new database, so I script-ed out the db and paste the script into new SP gui (SQL 2000). I want to pass it a variable for the data/log file location that is not the default location. The original script looks like this:
CREATE DATABASE [PWRR_DDS] ON (NAME = N'PWRR_DDS_Data', FILENAME = N'F:SQL SERVER FILESDatabasesdbName.mdf' , SIZE = 3118, FILEGROWTH = 10%) LOG ON (NAME = N'PWRR_DDS_Log', FILENAME = N'F:SQL SERVER FILESDatabasesdbName_Log.LDF' , SIZE = 5000, FILEGROWTH = 10%) COLLATE SQL_Latin1_General_CP1_CI_AS.
I replaced the path of the FILENAME variable like this:
CREATE DATABASE [PWRR_DDS] ON (NAME = N'PWRR_DDS_Data', FILENAME = @DBPath, SIZE = 5000, FILEGROWTH = 10%) LOG ON (NAME = N'PWRR_DDS_Log', FILENAME = @LogPath , SIZE = 5000, FILEGROWTH = 10%) COLLATE SQL_Latin1_General_CP1_CI_AS,
declaring the variables as char(500). The error I get is "Incorrect sybtax near '@DBPath'.
Any ideas for workaround?
Thanks,
EJM
View 1 Replies
View Related
Dec 31, 2006
I have a raw file destination and am using a variable to store the filename. In an earlier task, I create the value in the variable. User:Filename ... set to C:Test.txt.
When I run the package, I get the "Error: 0xC0202070 at DFT Tekelec Call Events, RFD Tekelec [1365]: The file name property is not valid. The file name is a device or contains invalid characters". error. I then set a breakpoint to examine my variables on the DataFlow pre-execute event and found my variable showing the value "C:\Text.txt" ... so apparently XMLA is adding the escape character when it stores the value in the variable but not retracting it when it uses the value as the filename.
What am I missing? Can I not use pathing in the variable? And if that's the case, how do I specify a path. Went back through my Rational Guide to Scripting SSIS but did not find this addressed specifically ... my second option being build the fiilename by script and set the raw file destination property directly via script.
View 3 Replies
View Related
Oct 19, 2015
I have one package through for each loop container I am loading all flat files into  target table and its working fine.Now I my requirement is to  capture the .txt file and loading into sqlserver table.Please check below file name.
CCCLOC_DDDLOC_LOC_20151203_240000_trigger.txt
from above file name I have to derived below detail.I have variable @File_Name which is used to stored the file name at rune time.Now I want to derived 5 values from the file name as below
Clientname=CCCLOC
Partnername=DDDLOC
Entity=LOC
Creationdate=20151203
Creationtime=240000
how to write expression for above situation.
View 10 Replies
View Related
Sep 3, 2007
Hi,
I am migrating one of my DTS package to SSIS.
My task is to read the filename from a database table and transfer the flat file data in to a table.
In SSIS,I am able to fetch the file name using a Data Reader Source; but how to pass this fileName parameter to Flat File Source ?
In DTS I have used ActiveX script to pass filename variable as flatfilecon.Source.
Any help ?
Thanks,
Ravi
View 4 Replies
View Related
Sep 7, 2007
Doesn't appear you can do this.
Am I wrong?
Please tell me I am.
View 11 Replies
View Related
Jul 28, 2015
I have a string variable and following data.
Declare @ServiceID varchar(200)
set @ServiceID='change chock','change starter','wiring for lights','servicing'
when I assign values in @ServiceID Â in the above manner then it shows error. How to get string array in @ServiceID variable so that i can go ahead.
View 8 Replies
View Related
Oct 4, 2015
I am studying indexes and keys. I have a table that has a fixed width of data to be loaded in the first column which is parsed in a view based on data types within the fixed width specifications.
Example column A:
(name phone house cost of house,zipcodecountystatecountry)
-a view will later split this large varchar string basedÂ
column b: is the source filename of the data load (varchar 256)
....
a. would there be a benefit of adding a clustered or nonclustered index (if so which/point in direction on why)
b. is there benefit of making one of these two columns a primary key (millions of records) or for adding a 3rd new column as a pk?
c. view: this parses the data in column a so it ends up looking more like "name phone house cost of house zipcode county state country" each having their own column.
-any pros/cons of adding indexes (if so which) to the view instead of the tables or both for once the data is parsed?
View 4 Replies
View Related
Apr 19, 2008
Hi Champs,
Scenario Configuration : VB.net 2005 Code, WebService for Executing SSIS on Server, SSIS deployed on the Database Server
Problem Description : We are developing windows applicaiton in which we call webservice which was deployed on the same server where SSIS packages are deployed.
Now from Code we are passing FilePath name in variable and execute the Package. But the SSis result says that
The file name "\computernamefol1fol2fol3fol4abc.txt" specified in the connection was not valid.
More Information:
1. Full Permission are given on this network folder.
2. Package executes successfully from SSIS development solution (BIS solution)
3. Deployed packed executes successfully from the Database Server.
4. From Development pc packege executes successfully.
5. Other packages deployed on the same server executed suucessfully with same configuration and scenario.
Only this package is not executing.
-- the only differece with this package with other is -
using ".txt" extension in Flat file connection and using VB Script task
Can any one suggest the appropirate solution for this problem...
Thanks
Tarang Pandya
View 21 Replies
View Related
Mar 26, 2002
Hi there,
Following is the code I have, which I select and execute as one batch.
declare @intData integer
Declare @strSQL varchar(8000)
Set @strSql = ''
set @strSql = 'select @intData = Age from MasterRecords'
exec (@strSql)
I get the following error in SQL 2000's query analyzer.
Must declare the variable '@intdata'.
Any and all help is highly appreciated.
View 1 Replies
View Related
Jun 5, 2000
Hi,
Does anyone know what is the maximum size for a string variable that can be used by Execute statement in SQL 7 and SQL 6.5? If I really need to execute
a long statement around 9000 characters long, how can I do it?
declare lcsql varchar(x) && what is the maximum size for x in SQL 7 and SQL 6.5
select lcsql = 'select ...'
execute (lcsql)
View 1 Replies
View Related
Aug 17, 2007
Hi
I have a problem with a string variable which looks something like this
@VARIABLE = 'RTY,YTUK,GHJ'
I need to be able to select (RTY) the first individual values seperated by the commas to be used as a variable elsewhere in my SQL script.
Following this I need to use the second value (YTUK) to be run in the same piece of code. Followed by the 3rd value (GHJ)
Can anyone tell me how to do this?
Thanks
View 2 Replies
View Related
May 11, 2008
hi there,
i am trying to pass a string which contains a string,
here is the code which is wrong :
{string sqlcommand = "select pnia.pnia_number, pnia.user_name, pnia.date_pnia, pnia.user_pnia, problem.problem, gormim.gorem_name, status.status_name from pnia,gormim,problem,status where (pnia.status='@p1' and status.status='@p1' and pnia.problem=problem.problem_num and pnia.gorem=gormim.gorem)";
OleDbCommand cmd = new OleDbCommand(sqlcommand,con);OleDbParameter p1 = new OleDbParameter("@p1",this.DropDownList4.SelectedItem.Value.ToString());
cmd.Parameters.Add(p1);
}
the problem is that the sql compailer doesnt take the parameter (@p1) as a string
if someone could help me with that it would be great ! tnx
View 2 Replies
View Related
Dec 5, 1999
Using SQL Server 7.0, I am trying to use a variable string called from a form to perform a simple query.
Here's what it looks like:
[after submitting a form on the previous page with a drop down list box titled "fiscal"]
dim strYear
strYear = Request.Form("fiscal")
sql = "SELECT * FROM VENDOR WHERE STATUS = 'P' AND '"& strYear &"';"
[where strYear is the following: PYMNT_DT > ''12/31/98'']
Records exist that meet this criteria. If the PYMNT_DT > '12/31/98' is hardcoded into the sql statement, 12 records are returned. However, when the variable string is used instead, no records are found. Any ideas on how this problem might be fixed?
Thanks in advance.
Sincerely,
Chad Massie
View 1 Replies
View Related
May 9, 2014
I want to run the following code:
Declare@Testnames as Varchar(500)
Set@Testnames = ('CT,MRI')-- List all radiology type
SELECT*
FROMRPT_OUTPATIENT_IMAGING
WHEREservice_level2 In (@Testnames)
Nothing comes back.
When I run:
SELECT*
FROMRPT_OUTPATIENT_IMAGING
WHEREservice_level2 In ('CT','MRI')
Then I get results.
View 5 Replies
View Related
Jun 29, 2007
Is there a way around the character limit for a variable? I'm throwing the following in a variable and evaulating it as an expression and having an execute sql task do it, but I can clearly see it's being cut off.
"insert work.dbo.data_run select publisher,publisher_db,subscriber,subscriber_db,article,null,getdate(),null
from msdb.dbo.sysreplicationalerts
where error_id<>0
and alert_error_code=20574
and [time] between '" +(DT_STR,50,1252)@[System::ContainerStartTime] +"' and '"+(DT_STR,50,1252)GETDATE()+"'"
Thanks,
Phil
View 7 Replies
View Related
Nov 17, 2007
i have string variable as,
String str="Int";
now, while assigning sql parameters, i want
param.SqlDBType=SqlDBType.Int;
but, value of Int is dynamic. it may be string or double so,
i want it to be as,
param.SqlDBType=(SqlDBType)str;
but its not acceptable(its invalid cast).
in any way can i do it and how?
regards---
View 1 Replies
View Related