sql-server-2012

Join Remote database table with my Local database table in SQL Server 2012

痞子三分冷 提交于 2019-12-13 05:42:56
问题 I am using SQL Server 2012 Management Studio. I tried to connect to a remote database. I was able to connect successfully but i was restricted to access only for four views. I tried the following steps to join the table with my local table. I tried to use linkedserver but I was un-able to add the remote server due to permission restriction so i was un-able to modify the SP_LinkedServer . I tried to copy the table but i was un-able to copy it to my local database. I am planning to compare my

INSERT statement cannot contain a SELECT statement -sql server2012

自古美人都是妖i 提交于 2019-12-13 05:05:36
问题 declare @us table(name nvarchar(100),lastname nvarchar(100),UID bigint,available bit); declare @Name nvarchar(100), @lastname nvarchar(100), @UID bigint, @Avail bit insert into @us select @name=name,@lastname=lastname,@UID=UID,@Avail=available from Users where available='1' select * from @us I got this error An INSERT statement cannot contain a SELECT statement that assigns values to a variable. I searched for this problem but many people used queries like this and they said there is no

SQL Server 2012: JOIN 3 tables for a condition

假装没事ソ 提交于 2019-12-13 04:52:20
问题 I have 3 tables: TABLEA (ID INT, name VARCHAR(2)) ID Name 01 A4 01 SH 01 9K 02 M1 02 L4 03 2G 03 99 TableB(Name VARCHAR(2)) Name 5G U8 02 45 23 J7 99 9F A4 H2.... TableC(ID INT, Name VARCHAR(2)) (prepopulated with ID from tableA) (same number of records as A) ID Name 01 NULL 01 NULL 01 NULL 02 NULL 02 NULL 03 NULL 03 NULL I want to populate C.Name from B.Name so that for same ID (say 1), it should have different values than A.Name . So, C.Name can not have (A4, SH, 9K) for ID = 1 because they

TSQL Replace value in XML String

妖精的绣舞 提交于 2019-12-13 04:48:03
问题 I have a field within my table that contains optional fields of data contained as XML. One of those fields is editable in my UI and I am trying to update that node / value within the block of XML. Here is what I have: UPDATE dbo.TFS_Feedback_New SET Details.modify('replace value of (/optional/educational/text())[1] with "@updatedEducation"') WHERE feedbackID = @FBID The issue is, I need to pass the replacement as a variable. When I have it as is, it puts in @updatedEducation as the field

Conditional join to two different tables based on 2 columns in 1 table

流过昼夜 提交于 2019-12-13 04:41:54
问题 I have a table that looks like this dbo.Box ID SourceID OverrideQueueID 1 1 NULL 2 1 2 3 2 NULL I need to figure out a way to say if the OverrideQueueID IS NULL then just do a join from dbo.Box to dbo.Source.ID, otherwise if OverrideQueueID IS NOT NULL join to the dbo.Queue.ID instead. Is this possible to do in one select since it is joining to different tables? I am trying to do this without introducing a bunch of left joins if at all possible. 回答1: I hope a union will help you, like given

How to add header columns based on data fetch from the database in gridview

笑着哭i 提交于 2019-12-13 04:22:41
问题 I have a GridView and want to make headers dynamically based on the some SQL query like... select question from quiz where quizid is 123. This query will return * number of questions based on the quizid . How to create headers with the data that's been selected from database? 回答1: You can use DataTable to help with this. I don't know which technologies you used for database management, but I used LinQ to SQL . And the following is my sample: DataClassesDataContext db = new

MSSQL query no longer works with Windows 10 client: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value

淺唱寂寞╮ 提交于 2019-12-13 04:12:11
问题 We have been using the following SQL query for a long time in a WinForms program with no problems, until some end users upgraded to Windows 10. They suddenly get the exception:"ERROR [22007] [Microsoft][SQL Server Native Client 11.0][SQL Server]The conversion of a varchar data type to a datetime data type resulted in an out-of-range value." This error has been posted to inside here earlier, but I did not find any post where the occurrence was connected to a Windows 10 upgrade. The query is

SQL Server c# connection

时光总嘲笑我的痴心妄想 提交于 2019-12-13 03:58:55
问题 So Im running a Sql Server 2012 in a virtual machine on my computer and I want to be able to connect on it with the SqlConnection on Visual Studio, but I have no idea what to put on the servername parameter. I dont know if I have to put the vm ipaddress or the machine address "WIN-NIJ53etc\SQLEXPRESS" 回答1: UPDATED: FOR MIGRATING BETWEEN SQL CE AND SQL SERVER: Please take a look at this instruction here. You should follow these steps: 1- Set the virtual machine to have a physical IP address.

How to get range time in sql server

微笑、不失礼 提交于 2019-12-13 03:51:54
问题 Basically what I want try to do is to get shift in range between already get with this where where @param_value_from_hour between From_Hour and To_Hour it works when @param_value_from_hour let say 16:00 but what if I have to search @param_value_from_hour with 19:00? 回答1: If the logic is that, if the end of the period is earlier than the start of the period then the period is assumed to span midnight (if it isn't, we need some other form of convention or things get hopelessly ambiguous): where

Clients Reports from web app

耗尽温柔 提交于 2019-12-13 03:43:25
问题 I have an web app with some static reports that is running with SQL Server 2012 Web Edition and I dont want the impact of a report process on usage of the app. So, I decide to split the database: Database Master - With all data. Used for all web app precess, except the reports Database X - With all data from the client X. Used only for report and updated every day. Database Z - With all data from the client Z. Used only for report and updated every day. Database Y - With all data from the