Executing Multi-lines SQL Scripts From Command-line
Jul 20, 2005
Hello,
I'm trying to execute a file containing few SQL statements.
CREATE VIEW test1 AS SELECT * FROM table1;
CREATE VIEW test2 AS SELECT * FROM table2;
The standard SQL way is to end a statement with semi-colon.
But doing that,it doesn't work in SQL Server.
After changing ";" to "GO", it works fine.
Is there anyway we can stick to ";" to indicate the end of statement.
I don't want to create scripts which works only in SQL Server.
Please comment.
Thanks in advance.
View 3 Replies
ADVERTISEMENT
Jan 8, 2008
I see a weird behaviour when the package is executed as a SQL Server job and via command line. The package has environment variables configured. So when I run the package via a command line it picks up the user environment variables and gets executed fine with success. But when the package is scheduled as a job, it fails as it is not picking up environment variables. Does the SQL server has to be restarted to pick up the environment variables? I dont understand the reason of not picking up the environment variables when the package is run as a job. The job runs as the same user as the command line and the user variables are set for the environment variables. The logging is enabled on the package and I can see that it is logging as the same user even if its command line execution or executed as a job. Could you please anyone can explain why the package fails as a job and doesnt fail via command line. I am fighting with this for a long time.
Thanks
View 5 Replies
View Related
Sep 23, 2015
How do I execute below scripts using CMD:
Please Note: SQL server 2008r2, default instance with window Authentication.
1. Select * from Adventurewoks2008.Person.Person where Id = 5
2. Exec usp_getemployee (with parameter Manager_id = 100)
3. I have a folder named 'MyFolder' which contains 3 store procedures (usp_A, usp_B and usp_C).
How do I execute all 3 using CMD against AdventureWorks database.
View 9 Replies
View Related
Aug 31, 2007
I hope I'm posting this in the correct forum (forgive me if I'm not) since I'm not sure if this is an issue with inserting an item into a db or the processing of what I get out of it. I wrote a basic commenting system in which someone my post a comment about something written on the site. I wanted to keep it very simple, but I at least want the ability for a user to have newlines in their comment without having to hardcode a <br /> or something like that. Is there a way for me to detect a newline if someone, for example, is going to their next paragraph?
Let me know if you need a better explanation.
Thanks in advance!
View 4 Replies
View Related
Jan 27, 2008
I am generating hundreds of lines of sql with a tool and wish to execute is in runtime. The sql consists of table creation, procedure creation, aswell as inserts and updates. When i try with SqlDataAdapter I get an error. Does anyone have a solution on what I can do?
View 2 Replies
View Related
Feb 13, 2008
I create a rdlc file that contains a line chart with 3 lines that will plot in it. I put the proper data field in "series" and everything plots fine, except I get a spurious line that goes from the end of one line to the start of another line (or possibly back to itself, I can't tell). In another line chart I have 3 lines but get 2 spurious lines.
Anyone know how this happens or how I can fix it? The data is ordered and I don't see anything that would cause this..
Thanks,
Craig
View 1 Replies
View Related
May 25, 2005
Hi,
how to skip lines while procedure executing by other user ?
example
create sp_test
as
--#1
delete from x where a = 1
--#2
delete from x where a = 2
--#3
delete from x where a = 3
--#4
select * from x
user A executing sp_test
if user B executing sp_test at the same time run sp_test but skip #1; #3
Thanks
Alex
View 1 Replies
View Related
Feb 13, 2008
I am creating a simple line chart using SSRS 2005. The chart will display date vs. cumulative enrollment. In the line chart I want to display two lines. One line represents expected enrollment data and the other represents actual enrollment data. I would like the expected data line to be a dashed line and the actual line to be a solid line. I have a single dataset that contains data for both lines. I have added a column to the dataset that acts as a flag to indicate whether the data point is expected or actual. I have dropped the enrollment field from my dataset into "Drop data fields here". I have dropped the date field from my dataset into "Drop category fields here". I have dropped the flag field from my dataset into "Drop series fields here".
When I change the style of the series it changes the styles of both lines. How can assign a different line style to each line? Is this even possible with the way I have set up the chart? Is there another way to set up the chart to accomplish what I am trying to do?
View 1 Replies
View Related
Mar 11, 2008
I need to, ultimately, create a flatfile for exporting insurance information to a third-party vendor. Each individual is to have no more than 1 line per file, which contains their coverage information, if any, on 4 different type of insurance. What i need is for 2 fields in a table to determine the output for multiple fields in the flatfile.
What I have so far works, to an extent. If I have insurance types 1, 2, 4 (of types 1-4) required output is (__ = 2 blank spaces):
1A 1B 1C 1D 1E 2A 2B 2C 2D 2E 3A 3B 3C 3D 3E 4A 4B 4C 4D 4E
== == == == == == == == == == == == == == == == == == == ==
Y N __ MD XX Y N __ MD XX N __ __ __ __ Y N __ DN XX
If they have coverage, A always = Y, B always = N, C always = blank(null), D is their ins. type, E is their cov. type(CASE statement). if they DON'T have that type of coverage, A always = N and the remaining field are NULL.
After a lot of work, and scouring a forum or 2, I attempted a whole lot of CASE functions. Below is an sample of code representing the 1x statements. This same code is repeated 4 times with the 1x being altered with 2x, 3x, 4x.
CASE HB.PLAN_TYPE
WHEN '10' THEN 'Y'
ELSE 'N' END AS 1A,
CASE HB.PLAN_TYPE
WHEN '10' THEN 'N'
ELSE ' ' END AS 1B,
' ' AS 1C,
CASE HB.PLAN_TYPE
WHEN '10' THEN HB.BENEFIT_PLAN
ELSE ' ' END AS 1D,
CASE HB.PLAN_TYPE
WHEN '10' THEN (CASE WHEN HB.COVRG_CD ='1' THEN 'XX'
WHEN HB.COVRG_CD ='2' THEN 'YY'
WHEN HB.COVRG_CD ='3' THEN 'ZZ'
ELSE 'WW' END)
ELSE ' ' END AS 1E,
It works to an extent. While the desires/required output it above, the output this produces (same scenario) is:
1A 1B 1C 1D 1E 2A 2B 2C 2D 2E 3A 3B 3C 3D 3E 4A 4B 4C 4D 4E
== == == == == == == == == == == == == == == == == == == ==
Y N __ MD XX N __ __ __ __ N __ __ __ __ N __ __ __ __
1A 1B 1C 1D 1E 2A 2B 2C 2D 2E 3A 3B 3C 3D 3E 4A 4B 4C 4D 4E
== == == == == == == == == == == == == == == == == == == ==
N __ __ __ __ Y N __ MD XX N __ __ __ __ N __ __ __ __
1A 1B 1C 1D 1E 2A 2B 2C 2D 2E 3A 3B 3C 3D 3E 4A 4B 4C 4D 4E
== == == == == == == == == == == == == == == == == == == ==
N __ __ __ __ N __ __ __ __ N __ __ __ __ Y N __ DN XX
While there is supposed to be 1 line, regardless of number of insurance types, it only produces 1 line per type. I first tried this in Access, and was able to get it to work, but it required multiple queries resulting in a crosstab, export to Excel and manually manipulate the data, export to text file to manipulate, import back into Excel to manipulate, import back into Access and finally export into a flatfile. Far too much work to produce a file which is why I'm trying to convert it to raw SQL.
Any assistance in this matter would be greatly appreciated.
View 5 Replies
View Related
Dec 1, 2015
I have this query:
SELECT
ID1,
ID2,
type,
(case when type = '1' then sum(value) else '0' end) as Value1,
(case when type = '3' then sum(value) else '0' end) as Value2,
(case when type <> '1' and type <> '3' then sum(value) else '0' end) as Value3
FROM table1 WHERE ID1 = 'x' and ID2= 'y'
GROUP BY ID1, ID2, Type
Which returns:
ID1 ID2 Type Value1 Value2 Value3
005 11547 0 0.00 0.00 279.23
005 11547 1 15.23 0.00 0.00
005 11547 3 0.00 245.50 0.00
And I want to obtain this result:
ID1 ID2 Value1 Value2 Value3
005 11547 15.23 245.50 279.23
View 5 Replies
View Related
Mar 27, 2008
I have used the following useful article regarding exporting a multi-record file:
http://vsteamsystemcentral.com/cs21/blogs/steve_fibich/archive/2007/09/25/multi-record-formated-flat-file-with-ssis.aspx
I have created the 9 datasources, ordering each on a field commmon to all.
I have created the required derived columns headers and have merged all the record types into a file.
The resulting file looks fine, except for the odd blank line between record types. Any ideas regarding cause and what to do to fix?
Any help is most appreciated!
View 10 Replies
View Related
Jan 29, 2008
Can this be done in SSRS or must it be done in the query? Ideas? Suggestions? See Example Below:
Current table look:
1 Data.........
2 Data.........
3 Data.........
4 Data.........
5 Data.........
6 Data.........
7 Data.........
Etc...
The Way I need it to look
1 Data.........
2 Data.........
3 Data.........
4 Data.........
5 Data.........
6 Data.........
7 Data.........
Etc...
TIA (Thanks in Advance!)
View 4 Replies
View Related
Sep 28, 2004
Hi,
I have a Multiline Textbox in my application.The value from the textbox is updates in a SQL
table.The problem i have is
If I type in the textbox 1211 London street Sussex <br> UK <br>Europe ,only 1211 London street Sussex gets into the table.Anything I type after the "Enter " doesnot go into the table.
I checked the field sizes in my stored procedure and they are varchar(500) .
Any ideas
View 4 Replies
View Related
Aug 30, 2005
Is it not possible to have a multi-line annotation OR my ENTER key is stuck ;-)
View 7 Replies
View Related
Jul 10, 2006
Using Visual basic 2005
I have a form and set up my datasource, bindings etc.
All works well, adding, updating, and deleting via form to sqlexpress except.....
I have 2 columns set up in sqlserver that get data from muliline textboxes on my form.
Column 1 "Material" is nvarchar(50)
Column 2 "Quantity" is int
The first multine textbox "Material" works fine, eather updating in the textbox or in the Datagridview cell.
the second multiline textbox "Quantity" works when I just put in a number in the first line of the multiline textbox, when I put in the 2nd number on the second line, nothing gets updated.
I I do that in the datagridview cell (Shift-Enter), I get an error.
"System string was not in correct format".
I tried integer.parse, but that dosn't work. I'm assuming it has something to do with the next line ascii code or something like that.
Can anyone out there help with this
View 3 Replies
View Related
Feb 28, 2008
Hello,I'm a newbie and I have a little problem that's starting to work on my nerves I want to store a multi line textbox in the database, just like the way it has been entered.I used a varbinary-field.This is my code in my aspx Dim myOptions As New InterTyp.Opties() Dim myCon As SqlConnection = myOptions.getCon() Dim cmdOef As SqlCommand Dim parmOef As SqlParameter cmdOef = New SqlCommand("GetOef", myCon) cmdOef.CommandType = CommandType.StoredProcedure cmdOef.Parameters.Add("@oid", System.Data.SqlDbType.Int).Value = ID 'output parmOef = cmdOef.Parameters.Add("@otext", SqlDbType.VarChar) parmOef.Size = 8000 parmOef.Direction = ParameterDirection.Output 'execute the query myCon.Open() cmdOef.ExecuteNonQuery() txtOef.Text = cmdOef.Parameters("@otext").Value myCon.Close()In my code i call a sp:CREATE PROCEDURE dbo.GetOef @oid integer, @otext varchar OutputAS SELECT otext FROM oefening WHERE (oid = @oid) So my problem is:How do i cast the varbinary back to a text?
View 2 Replies
View Related
Apr 23, 2007
Good day,
Is there anyway that I can have a multi-line chart title? I have even tried placing a text box over the title part of the chart that is multi-line, although this appears to work once the report is deplyed and viewed in a web browser the text box appears below the chart and the chart then has no title.
Please can you help?
View 2 Replies
View Related
Apr 14, 2014
How to update column with multiline comments.
eg. I need to update Notification column in my table as below.
Exit Formalities Notification sent to:
Employee: LastName, FirstName
EmployeeEmail: EmployeeEmailAddress
View 4 Replies
View Related
Jul 23, 2005
Using Query Analyzer, I can right click on an object and select "scriptobject to new window as create" and I get the text of the object'sdefinition (schema). Can I get same result from command line, i.e., fromosql, I can get text output for the definition of the object (something likedefncopy under Sybase)? If so, what is the command or store procedure name?Thanks in advance.
View 2 Replies
View Related
Apr 2, 2008
Is there any command line that I can use to do select from databases (SQL 2005)
View 4 Replies
View Related
Jan 5, 2004
hi.
I must get i trigger the sql command, which execute trigger.
View 5 Replies
View Related
Jul 20, 2005
Here is the block of the sproc that I?ve created. All lines executefine except for the ?exec master..xp_cmdshell @reboottc?. In order tomake this work from the query analyzer I had to set the MSSQLSERVERservice to have the same credentials as the thin clients we are tryingto shut down, that means the service is running as an Administrator onthe sql server with the same u/p as administrator on thin clients.declare @RoomNumber varchar(6) -- for testingset @RoomNumber = '1144' -- for testingDECLARE @RoomIP varchar(15), @RebootTCvarchar(120), @shutdownStart varchar(20), @shutdownEnd varchar(85)-- @ShutDownStart and @ShutDownEnd will be usedwith the @RoomIP to build the shutdown command sent to the thinclientsSET @ShutDownStart = 'shutdown -r -f -m \'SET @ShutDownEnd = ' -t 5 -c "MandatoryiConnect Reboot issued during guest check in/out process"'SELECT @RoomIP = IP FROM Rooms WHERERoomNumber = cast(@RoomNumber AS INT)SET @RebootTC = @ShutDownStart + @RoomIP +@ShutDownEnd-- print @RebootTC -- for testing-- @RebootTC ends up looking like the line below based on the@RoomNumber-- shutdown -r -f -m \172.18.16.103 -t 5 -c "Mandatory iConnectReboot issued during guest check in/out process?-- Also the command below runs correctly when executed from SQL QueryAnalyzerEXEC master..xp_cmdshell @RebootTC
View 1 Replies
View Related
May 1, 2001
hi I would appreciate if someone demonstrate how to automate ftp in a command line from within a batch file. I do want to move certain files from one server to another via ftp command line in an automatic fashion via running the batch periodically.
thanks
Ali
View 1 Replies
View Related
Jun 13, 2000
hi: I can't seem to run BCP thru the command line.
bcp pubs..authors out c:authors.txt -c -Usa -P
error:
Msg 170, Level 15, State 1, Server Y47SA, Procedure , Line 1
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near'.'.
I've been trying to run BCP thru command line all day. I tried OSQL, ISQL. I find this utility very
frustrating. btw - I have installed SP2.
any thoughts would be much appreciated.
TIA
deanna
View 5 Replies
View Related
Sep 25, 2002
Anyone know where I can find some command line tools such as RCMD etc.. Thank you.;)
View 1 Replies
View Related
Sep 22, 2005
I'm trying to insert into a table 2 values one of which is an
exec master..xp_cmdshell @command where I have assigned @command with a value
this statement gives me the result into a 1 col. table fine:
insert into mytable99(col1) exec master..xp_cmdshell @command
now what I want to do is put col2 in there as well!!
ie. insert into mytable99(col1,col2) values (exec master..xp_cmdshell @command, '123')
I get a sytax error ... on the exec ??
Could anyone help re the proper way of doing this ... thanks in advance
View 1 Replies
View Related
Oct 13, 2005
I use a similar command below to insert into a temp table the result of a large command line call to an exectable with many parameters passed in the command of which the result passed back contains many items. I then parse the response string to get my results...
set @command = 'dir'
insert into tsverisign(response) exec master..xp_cmdshell @command
My question is our can I insert two values at the same time to this same table one of which is my "exec master..xp_cmdshell @command"
similar to insert into tables (field_a, feild_b) values ('1','2')
Something like (and I know this does not work):
insert into tsverisign(response,trans_id)
values (exec master..xp_cmdshell @command, '123')
Any help would be greatly appreciated .... PS I'm new to MS SQL 2000 and proper syntax etc. etc. so I need full example so I can try. :rolleyes:
View 1 Replies
View Related
Jun 11, 2007
Hi All,
I was given a task of coming up with the script to recreate an existing database using a command line. I would use this script in case when the server is down and I can't get to Query Analyzer or EM to recreate it. I am not sure where to start. Any ideas are greatly appreciated.
Thanks.
View 5 Replies
View Related
May 21, 2004
What ius the synthax to backup an SQLServer DB from the command line ?
Thanks
View 1 Replies
View Related
Jan 29, 2008
Can someone give me the command to restart SQL?
Thanks
View 1 Replies
View Related
Jul 23, 2005
I want to restore a backup copy of a database from the command line. Canthis be done?Thanks, Tom.
View 2 Replies
View Related
Jul 20, 2005
Hi Sir:Is any possible to run DTS package from Command Line ?Lucas
View 1 Replies
View Related
May 4, 2007
I am trying to create an quiet install for SQL Server Express. The install is being run under a local administrators account. However, when a user, who is only in the local users group, accesses the application using ClickOnce deplolyment, it says SQL Server Express Edition is not installed.
-Dan
View 1 Replies
View Related