SQL Express Import Using Transact SQL Statements
Aug 2, 2006I have SQL server Express. How can you import a database, using transact sql code, onto a server from your local PC.
View 11 RepliesI have SQL server Express. How can you import a database, using transact sql code, onto a server from your local PC.
View 11 RepliesI need to breakdown some information with just initials (sometimes 2, sometimes 3 if the initials are already used) SQL Server throws the error of:
Msg 125, Level 15, State 4, Line 1
Case expressions may only be nested to level 10.
What should I alter, or how should I write this query so I can use all of the needed case statements? (their are actually about 24 when statements, but this is just to get a working example to display)
Select
case
when employee_name Like 'Jorge Jones' Then 'JJ'
when employee_name Like 'Mike Mikes' Then 'MM'
when employee_name Like 'Albert Alvarez' Then 'AA'
when employee_name Like 'Hernandez-Sotata' Then 'HS'
[code]....
I have a database with two tables (Table1 and Table2)
looking for something like:
Table1:
+----+-------+----------+
| id | Name | email |
+----+-------+----------+
| 1 | name1 | mail1 |
| 2 | name2 | mail2 |
| 3 | name3 | mail3 |
| 4 | name4 | mail4 |
| 5 | name5 | mail5 |
| 6 | name6 | mail6 |
+-- +-------+----------+
Table2:
+----+------------+---------+------+
| id | table1_ID | fee | type |
+---+-------------+---------+------+
| 1 | 1 | 20000 | 1 |
| 2 | 3 | 1000 | 1 |
| 3 | 1 | 10000 | 1 |
| 4 | 3 | 1000 | 1 |
| 5 | 5 | 500 | 1 |
| 6 | 5 | 500 | 2 |
| 7 | 1 | 60000 | 2 |
| 8 | 2 | 1000 | 2 |
+----+------------+---------+-------+
i want the query that return:
+--------+-------+---------------------------------+---------------------------------+--------+
| name | email | a:sum(fee) where type=1 | b:sum(fee) where type=2 | b/10 |
+--------+-------+---------------------------------+---------------------------------+--------+
|name1 | mail1 | 30000 | 60000 | 6000|
|name2 | mail2 | 0 | 1000 | 100 |
|name3 | mail3 | 2000 | 0 | 0 |
|name4 | mail4 | 0 | 0 | 0 |
|name5 | mail5 | 500 | 500 | 50 |
|name6 | mail6 | 0 | 0 | 0 |
+--------+-------+---------------------------+---------------------------------------+---------+
So I'm thinking if I can have multiple statements within the CASE-THEN..or do I have to CASE out each individually? Kind of like this....
CASE
WHEN [AddressType] = 'M'
THEN [MailingAddress].[Address1]
[MailingAddress].[Address2]
[MailingAddress].[City]
[MailingAddress].[State]
[MailingAddress].[Zipcode]
WHEN [AddressType] = 'D'
THEN [DefaultAddress].[Address1]
[DefaultAddress].[Address2]
[DefaultAddress].[City]
[DefaultAddress].[State]
[DefaultAddress].[Zipcode]
I am trying to generate a script to drop 15 tables which have dependencies across the database. Is there a script that could generate the drop stataments based on the child table first , parent table last strategy?
View 3 Replies View RelatedI am not sure if i am looking correctly at the deadlocks but i see deadlocks between two select statements.These statements are being run through an application. Below is the table schema from where the select is being performed
CREATE TABLE [dbo].[CMS_LOCKS7](
[PARENTID] [int] NOT NU, --we have a non clustered index on this column
[CHILDID] [int] NOT NULL, --we have a non clustered index on this column
[ISMEMBER] [int] NOT NULL, -- we have a non clustered index on this column
[ORDINAL] [int] NULL,-- we have a non clustered index on this column
[Code] ....
STEP1:
CREATE TABLE Trace(Statement VARCHAR(MAX))
INSERT INTO Trace
VALUES('select * from Account'),('select * from Account') ,('Select LastUpdated,Lastdeleted,LastInserted from History'),
('Insert into Account Select lastUpdated from History'),('Delete from OldAccount where LastUpdatedId=3'),('Delete from OldAccount where LastDeletedId=3'),('Delete from OldAccount where LastInserted=3'),('DROP TABLE BMP')
[code]....
now,when i run step3 ; i wanted to see if there is actually a delete or insert or select or update happens but as i used like %% (matching characters) i am getting all names matching with the % % , example row 7 in above is there a way i can use any wildcards and only find if there is actual delete, actual insert, actual select, actual update statement happening.
I have a table that keeps track of all changes that were performed in an application. There is a column called "old value" and column called "new value". There are some values in the application that don't require data therefore the "old value" or "new value" values can be empty. These columns are an nvarchar data type because the value can be text or numbers or dates. An example is "ReceivedDate". There is a report that is generated based on this table.
What is happening is the query in the report dataset is adding dates when it should be displaying empty. They query is using "CASE/WHEN/THEN". What I need is "When the column is "RecievedDate" and it is not null then convert it to a date". This is for formatting purposes.
This is an example of the table:
UpdateColumn
Old Value
New Value
ReceivedDate
7/8/2015 5:00:00 AM
ReceivedDate
7/8/2015 12:00:00 AM
7/9/2015 5:00:00 AM
ReceivedDate
7/9/2015 12:00:00 AM
So, the first time it was updated there was no value but it was replaced with July 8, 2015 and so on.This is what the report is displaying
This is the query:
CASE UpdateColumn
... WHEN 'ReceivedDate' THEN (replace(convert(varchar(11),CONVERT ( date, oldvalue ), 106), ' ', '-') )
...
I tried adding
CASE UpdateColumn
...
WHEN 'ReceivedDate' IS NOT NULL
THEN (replace(convert(varchar(11),CONVERT ( date, oldvalue ), 106), ' ', '-') )
...
But it did not like the "IS NOT NULL".
We are not allowed to write delete statement in a function. It will give the below error.
"Invalid use of a side-effecting operator 'DELETE' within a function."
We will get the same error for truncate/drop statements.
What is the reason behind this error?
I am working on an app that getting quite a few deadlocks due to delete statements. I have turned on the sql trace flags and pulled the offending delete statements out of the ERRORLOG and trying to mesh those up with the indexes defined on the table, etc. looking to see if there is anything that can be done strictly from the db side (no app code change) to reduce/eliminate these deadlocks. I have ran some tests/played around with RCSI and even disabling lock escalation but neither have improved my results.
What I have done is to search the errorlog file for DELETE FROM Tablename, output those matching lines, then sort of normalize the literal values to # or XYZ, open in Notepad++, removed trailing whitespace + dups and sort to come up with these results for the unique list of offending T-SQL statements (a LOT easier to read in text editor so sending screen cap.
Open this url in new tab [URL] ....
I have some old code consisting of over 30 Union statements, unioning 7/1/15-8/1/15 data according to the below code. Each block is the same except for the date. How could I rewrite these 30 union statements into a more concise query?
Each client (people_id) has a distinct agency_id_number. So the code below totals the number of distinct clients/day and groups them by programs and facilities.
Sample data that you can use to test this report:
IF OBJECT_ID(N'tempdb..#sample_census') IS NOT NULL drop table #sample_census
create table #sample_census
(
start_date datetime,
program_name varchar(25),
facility_name varchar(25),
agency_id_number varchar(25)
)
[Code] ....
I want to include GO statements to execute a large stored procedure in batches, how can I do that?
View 9 Replies View RelatedI have a database which will be generated via script. However there are some tables with default data that need to exist on the database.I was wondering if there could be a program that could generate inserts statments for the data in a table.I know about the import / export program that comes with SQL but it doesnt have an interface that lets you copy the insert script and values into an SQL file (or does it?)
View 7 Replies View RelatedI need to list out all the procedures which have select queries and does not use NOLOCK hint. Please note that there are more than 2000 sps and some sps have single select some have multiple, some does not have select queries at all. I need to find out only the ones which does not use NOLOCK hint in a select query.
View 8 Replies View RelatedI had to enable identity_insert on a bunch of tables and I have already done that. Now I need to modify my insert into select * from statements to include column list names along with identity columns for select as well as insert statements. The DDL is same but they are both different databases.There are almost 100 tables that it needs to be modified. Is there a way we can generate scripts for insert and select for each individual table along with their column lists including the identity column?
View 7 Replies View Related
Hi,
I am a newbie so i apologies beforehand for any mistakes i make on this forum.
Anyway, i created an asp.net website using the MS Visual Web developer tool. This has a couple of SQL SERVER databases within it.
I then latervinstalled the SQL SERVER management studio express in order to manage the SQL SERVER DBs that i had as part of my website but they do not appear within the management studio db list.
As this is the express version, is there anyway of importing the existing SQL SERVER dbs that i have to the management studio so i can manage them from there?
Regards,
Shuja.
I am getting an exception. And i don't know whether this exception is from the C# coding or SQL SERVER."Cannot roll back InsertRxs. No transaction or savepoint of that name was found.Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 0, current count = 1.A transaction that was started in a MARS batch is still active at the end of the batch. The transaction is rolled back."
View 2 Replies View RelatedHi,
I have recently started using sql server express edition in place of my oracle db instance and have a need to enable trace on this to view some of the selects that are being fired by the application. I am unable to find out how exactly this is done. I was taken to a couple of sites that said that I needed SSEUtil and have installed that also.
Could one of you gurus out there, please help me out as this is pretty urgent for me to find.
TIA
Is it possible within SQL Express stored procedures to redirect Print statements, along with other output messages to file?
In the following example I would like to redirect the output to a file (text or XML):
PRINT 'Droping Class Type Data Object...'
DROP TABLE ClassTypeRef
Output to Messages which I would like to redirect to a file:
Droping Class Type Data Object...
DROP_TABLE - dbo.ClassTypeRef
Thanks in advance,
Mark
I cannot find the problem with this function.
ALTER function [Event].[DetermineTrackTime](@TrialID varchar(max)) returns int as
begin
Declare @ret int;
Declare @EnterVolumeTime int;
Declare @ExitVolumeTime int;
Declare @StartTrackTime int;
[code]....
I am getting the following error on line 75:
Select statements included within a function cannot return data to a client.
This is happening when declaring TrackUpdateCursor
The compiler has no problem with the VolumeTimesCursor. What is causing this and what can I do about it?
I'm importing data from a table on one database into a table in another database on the same instance. The FROM database is collated as "Latin1_General_CI_AS" and the TO database is collated as "SQL_Latin1_General_CP1_CI_AS".
When I then try joining on a common nvarchar column between the 2 tables, I get this error:
Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AS" in the equal to operation.
Is there a way to change the collation of the incoming data as I'm inserting it into the TO table?
I have more than 500 CSV files with a similar structure [Same column name and same data format]. I would like to load these files in a database table on the SQL Server 2014 database.
View 21 Replies View RelatedI must import some exemplary file to database (MS Srrver 2000) ofcourseusing procedure Transact SQL.This file must:1.Read the xml file2. Create table3. Import this date from xml file to my databasePs. I create procedure who File xml imports to base, but unfortunately sheonly schedule when earlier create a table or table is created.So I need (Ithink) create such mini parser in language transact SQL.Does someone have some ideas?For every help Thanks==== example file xml ===========================================<root><Cust><IDosoby>1</IDosoby><Imie>Lukasz</Imie><Nazwisko>Przypadek</Nazwisko></Cust><Cust><IDosoby>2</IDosoby><Imie>Dariusz </Imie><Nazwisko>Mroz</Nazwisko></Cust><Cust><IDosoby>3</IDosoby><Imie>Tomasz</Imie><Nazwisko>Kolo</Nazwisko></Cust></root>================================================== =========--Luk
View 3 Replies View RelatedHello, I hope I am posting this question in the right forum. I have been working on some ASP applications and using them to connect to a MySQL database. I would like to move all of the data from MySQL over to SQL2005 Express. The problem is that the express version doesn't offer an import/export tool for CSV files. I am able to export my table data from MySQL to a CSV file, how can I import this data into my SQL2005 Ex database? Thanks.
Jim Miller
How do I Import excel file to SQL express
View 9 Replies View Relatedhow to import/export data with sql express?
View 7 Replies View Relatedhi,
i need to import excel data(2000 records) into sql server table.
i did all possible ways. but still i am getting the error
OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" returned message "Could not find installable ISAM.".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".
i used the query SELECT * FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0',
'Data Source=C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLdata.xls;Extended Properties=Excel 11.0',HDR=YES,Sheet1$)
and also
SELECT *
FROMOPENDATASOURCE('Microsoft.Jet.OLEDB.4.0', 'Data Source=C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLdata.xls;
Extended Properties=''Excel 11.0''')...[Sheet1$]
but no luck
i have configured linked server through management studio express.
can any one suggest me how to achieve this.
is there any easy way
Thanks
Hi There
Are there limitations to express and certificates, i can create certificates in express. But when i try to import a certificate from another server (developer edition) into my express edition i get his error:
The certificate, asymmetric key, or private key file does not exist or has invalid format
When i use the same certificate backup on non express editions it works 100% , is it not possible or must it be done differently ?
Thanx
I have an application using Express with a smallish user base that is moving to CE in version 2.
Is there some easy way I can move their databases to CE? They don't want to lose their history, and I don't blame them.
I'll code something if I have to, but I would rather do something administratively.
Thoughts?
Thanks!
S
Hi all,
In the VB 2005 Express, I can get the SqlConnection and ConnectionString of a Database "shcDB" in the Object Explorer of SQL Server Management Studio Express (SSMSE) by the following set of code:
///--CallshcSpAdoNetVB2005.vb--////
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Public Class Form1
Public Sub InsertNewFriend()
Dim connectionString As String = "Data Source=.SQLEXPRESS;Initial Catalog=shcDB;Integrated Security=SSPI;"
Dim connection As SqlConnection = New SqlConnection(connectionString)
Try
connection.Open()
Dim command As SqlCommand = New SqlCommand("sp_insertNewRecord", connection)
command.CommandType = CommandType.StoredProcedure
.......................................
etc.
///////////////////////////////////////////////////////
If the Database "shcDB" and the Stored Procedure "sp_inertNewRecord" are in the Database Explorer of VB 2005 Express, I plan to use "Data Source=local" in the following code statements to get the SqlConnection and ConnectionString:
.........................
........................
Dim connectionString As String = "Data Source=local;Initial Catalog=shcDB;Integrated Security=SSPI;"
Dim connection As SqlConnection = New SqlConnection(connectionString)
Try
connection.Open()
Dim command As SqlCommand = New SqlCommand("sp_insertNewRecord", connection)
command.CommandType = CommandType.StoredProcedure
........................
etc.
Is the "Data Source=local" statement right for this case? If not, what is the right code statement for my case?
Please help and advise.
Thanks,
Scott Chang
Where do I install the necessary files to get the import/export wizard to show up in sql express management studio? I have tried installing the SP1 Toolkit, the advanced services etc but I cannot get it so that I can right click on a database and 'import data' or 'export data' Thanks!
View 2 Replies View RelatedHi, please any one is expert in Data Base help me, i would like to import two Data columns from Excel file 2003 instead of two columns in a table in Sql Server Express 2005 , How Can i do that? and what is the way if I have Sql Developer 2005, thank you .
View 8 Replies View RelatedWhere is that neat little "Import/Export" DTS Wizard like I had in SQL Server 200 Developer?Or am I going to have to mess with the script generation features?
View 2 Replies View Related