sql-server-2008-r2

How to insert several fields into a table using ADO when two of the fields contain commas

若如初见. 提交于 2019-12-11 20:27:35
问题 I have an ado created recordset in access 2010 it returns 9 different fields from a stored procedure on sql server 2008 r2. I am trying to use this recordset (which does populate) to insert all of the records into a table that matches the output. My issue is that two of the fields are name fields that have commas in them. For example Smith, Joseph-- I need to insert that comma into the appropriate field. Right now it throws an error because of the comma in the field. Here is the code that I

create Scheduler task to invoke SQLCMD

末鹿安然 提交于 2019-12-11 20:13:37
问题 I have a Requirement where i have to run a SQL Script in SQL server on a weekly basis .Result of this script has to be mailed.I want to automate this process.I don't want to go with SSIS Jobs. I have searched i have found few options like Creating a Windows Scheduler task to invoke a SQLCMD.Can Someone Assist on how to create Scheduler task to invoke SQLCMD 回答1: Your best bet would be to create a Console Application which executes the SQL Command and performs the email. You can then use setup

Refresh View after table drop

时光毁灭记忆、已成空白 提交于 2019-12-11 19:45:28
问题 I have the following tables: Series One Tables: create table tbl1 ( id int, name varchar(100) ); insert into tbl1 values(1,'tbl1'); create table tbl2 ( id int, name varchar(100) ); insert into tbl2 values(1,'tbl2'); create table tbl3 ( id int, name varchar(100) ); insert into tbl3 values(1,'tbl3'); create table tbl4 ( id int, name varchar(100) ); insert into tbl4 values(1,'tbl4'); Series Double Tables: create table tbl11 ( id int, name varchar(100) ); insert into tbl11 values(1,'tbl11');

Right Approach to Insert in Table then copy it to another table

坚强是说给别人听的谎言 提交于 2019-12-11 19:27:03
问题 In my application a user will insert a book. For example someBook will be insert with 3 copies. Table1.BookID = 1, Table1.Copy = 3, Then in another table those 3 books will have their primary key so it will be Table2.AccessionID = 1,2,3 Table2.BookID = 1, 1, 1. This is what I current doing but a bad practice as what Aaron Bertrand said. int BookTitlesID; public void addBookTitle() { int copy = int.Parse(textBox2.Text); try { using (SqlConnection myDatabaseConnection = new SqlConnection

Replace substring specifically at the end of the character string in SQL

送分小仙女□ 提交于 2019-12-11 19:01:53
问题 In T-SQL, how do I replace the occurrence of a substring only at the end of a character string ( varchar )? For example: If I were to do the operation with substring violence on character string 'violence begets violence' , the result would be 'violence begets ' Some other examples are 1) 'the fox jumped over the fence' with substring fox would result in no change as fox is not at the end of the character string. 2) Can I kick the can with substring can would result in Can I kick the 3) gs_fs

Simple Update trigger + simple row insert

强颜欢笑 提交于 2019-12-11 18:57:43
问题 Total novice at triggers... all the docs don't bother with beginner stuff. I just want to update the row(s) that has/have been updated. My trigger below updates the entire table. The trigger below just tests two columns for changes. How do I restrict this update trigger to the update only the updated rows and not the entire table? ALTER TRIGGER [dbo].[geog_update] ON [dbo].[Site] FOR UPDATE AS SET NOCOUNT ON IF (UPDATE(Latitude) OR UPDATE(Longitude)) BEGIN UPDATE Site SET geog = geography:

jdbc stored png image at sql server 2008 r2 gives not complete data

萝らか妹 提交于 2019-12-11 18:18:47
问题 I want to save base64 image to my sql server 2008 r2, i used this: Connection con = Database.getConnection(); CallableStatement callableStatement = null; try { callableStatement = con .prepareCall("{call insertRestaurantFoodImage2(?,?)}"); callableStatement.setInt(1, ID); ; callableStatement.setString(2, stringImage); callableStatement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } the stored procedure to save the string is : ALTER PROCEDURE dbo.insertRestaurantFoodImage2

Increase row count in sql server after some count (say 25,000)

橙三吉。 提交于 2019-12-11 18:09:28
问题 I have table like this col1 col2 col3 3 5 8 4 5 5 5 5 5 3 3 3 4 5 6 I need to get table like below in SQL Server col1 col2 col3 group 3 5 8 1 4 5 5 1 5 5 5 2 3 3 3 2 4 5 6 3 After some row count (say 25000 ) group column row count has to increase (ex- if row count crosses 25,000 the group column value has to change to next number ie 25,001 - 2, 50001 - 3) How to write a query in SQL Server? 回答1: You can use row_number to generate numbers and the do some calculations. This will make on group

lock a table in sql server 2008 after select

耗尽温柔 提交于 2019-12-11 18:06:32
问题 I have a main currency table. Which has two fields, one currency Type and currency value. User can not be changed once a user start working with the DB. I need to lock my Currency table through SQL Server 2008 Query once user select one value. Can any one help me or suggest me for DB LOCK query. 回答1: You can use NOLOCK for your objects. For example : SELECT TOP 10 * FROM Orders WITH(NOLOCK) where UserName = 'VadaVici' 回答2: We had the same problem on a table in our database. Found this and it

Row-Number in Between Sub Query

…衆ロ難τιáo~ 提交于 2019-12-11 18:03:20
问题 select row_number() over (order by BookTitle) AS Row, BookTitleID, BookTitle, CallNumber, FullName, count(case Status when 'OnShelf' then 1 else null end) AS CopiesOnShelves from ( select Book.BookTitleID, BookTitles.BookTitle, BookTitles.CallNumber, Book.Status, FullName = LastName + ', ' + FirstName + ' ' + MiddleName From Book left outer join BookTitles on BookTitles.BookTitleID = Book.BookTitleID left outer join Authors on Authors.AuthorID = BookTitles.AuthorID ) sub Where Row between 1