sql-server-2005

BULK INSERT into table with Foreign Key

风流意气都作罢 提交于 2019-12-13 02:58:52
问题 I have a table Customer which has the details of the customer. The following are the fields CustId (PrimaryKey), Name, Date of Birth I have another table, the Asset information. The following fields are there - AssetId (PrimaryKey), AssetValue, CustId (Foreign Key Reference) My CSV file is as such Name, Date of Birth, AssetValue and I have to insert it into the two tables. I split the CSV file, one with the Name of Date of Birth and the other with just the AssetValue. Here is what I did - /

SQL Server: Unable to create relationship

ぐ巨炮叔叔 提交于 2019-12-13 02:57:48
问题 I was trying to create a table that has a one to many relationships. but it seems that adding a foreign key in Personal is not working. I am trying to link a Personal Information table to a address table? what is the solution for this error? Address table saved successfully Personal table Unable to create relationship 'FK_Personal_Address'. Cascading foreign key 'FK_Personal_Address' cannot be created where the referencing column 'Personal.ID' is an identity column. Could not create

send xml to sql

孤人 提交于 2019-12-13 02:45:25
问题 Can someone provide an example of how to send an xml from C# to SQL Server, and then loop on the xml in the stored procedure that got it, and update or enter line by line. 回答1: Check out the three-part series on SQL XML on 15seconds: http://www.15seconds.com/Issue/050803.htm. I would personally use the SQL XQuery functions to shred apart your XML into bits and pieces and store those in SQL Server. If you have something like: <data> <person> <name>Jones</name> <firstname>Peter</firstname> <

How do I downgrade a SQL 2008 MDF file for use in SQL 2005?

那年仲夏 提交于 2019-12-13 02:35:45
问题 Someone sent me a MDF file that was created in SQL 2008. I have SQL 2005, and the "Attach" function is rejecting the MDF file. How can I import this file? 回答1: You can't. You need to attach to a SQL 2008 instance and synch/BCP/SSIS the schema and contents. Blogged yesterday by Paul Randal referring to SQL Server 2008/SQL Server 2008 R2 differences 来源: https://stackoverflow.com/questions/1333145/how-do-i-downgrade-a-sql-2008-mdf-file-for-use-in-sql-2005

Scalar-Valued Function in NHibernate

流过昼夜 提交于 2019-12-13 02:15:21
问题 I have the following scalar function in MS SQL 2005: CREATE FUNCTION [dbo].[Distance] ( @lat1 float, @long1 float,@lat2 float, @long2 float ) RETURNS float AS BEGIN RETURN (3958*3.1415926*sqrt((@lat2-@lat1)*(@lat2-@lat1) + cos(@lat2/57.29578)*cos(@lat1/57.29578)*(@long2-@long1)*(@long2-@long1))/180); END I need to be able to call this function from my NHibernate queries. I read over this article, but I got bogged down in some details that I didn't understand right away. If you've used scalar

Stored procedure in SQL Server (order by desc)?

我是研究僧i 提交于 2019-12-13 02:14:51
问题 I have a stored procedure that will give the latest records i.e., order by added date this is my procedure.... select distinct top 5 videos.videoid,videos.videotitle,videos.videoname, convert(varchar,videos.posteddate,106) as posteddate,videos.approvedstatus, videos.videoimage,(ISNULL(videos.views,0.0)) as [views],videos.privacy, (isnull(videos.rating,0.0)) as rating,videos.userid, users.userid,users.username from videos left outer join users on videos.userid=users.userid where videos

SQL Server Reporting Services - http 403 forbidden - website declined to show this webpage

一笑奈何 提交于 2019-12-13 02:14:29
问题 Reporting Services was working fine until recently, now when I try to deploy and run a report from Business Intelligence Studio I get this error. Similarly when I try to connect to the ReportServer URL directoy from IE Explorer, (set to http:///ReportServer I get the same error, so it's not specific to the report but probably rather to the ReportServer or IIS configuration. I went through all the Properties of the website, comparing to another website on the same machine, and it seems

Concatenate with ORDER PRESERVATION

て烟熏妆下的殇ゞ 提交于 2019-12-13 02:14:26
问题 I have a table tblSomeData OrderOccurance ID Data -------------- -- ---- 1 1 HTMedia 2 1 Hedge 3 1 Bowing 4 1 FonWirelessLtd The first column "OrderOccurance" indicates in which order the elements i.e. Data will appear in the final output The Expected Output will be ID Data -- ----- 1 HTMedia,Hedge,Bowing,FonWirelessLtd I have done the below program Select ID , Data = stuff((Select ',' + Cast(Data As Varchar(20)) From tblSomeData t2 Where t2.ID = t1.ID for xml path('')),1,1,'') From

How to lock a table for inserting in sql?

孤街醉人 提交于 2019-12-13 02:08:17
问题 I have a web application in which I have a page named 'Data'. Many people will try to insert data into the table at a given time. So the reference no other than the primary key will get duplicated which should not be permitted. For inserting the data into the DB table, I am using a stored procedure in SQL. In my vb.net web application I am using Business layer with enterprise library for calling the stored procedure. Now I want to lock the table for inserting so that when multiple users

Dynamic Pivot (in SQL Server 2005)

被刻印的时光 ゝ 提交于 2019-12-13 02:05:27
问题 I'm writing a stored procedure for Microsoft SQL 2005 and I want to create a dynamic SQL Pivot: SELECT Book.ISBN, Book.Name StockMutation.StockLocation FROM Book INNER JOIN StockMutation AS sm ON Book.bookid = sm.bookid PIVOT ( COUNT(sm.NumberOfBooks) FOR sm.StockLocation IN (...) ) Preferable I want to replace (...) with: SELECT StockLocation.StockLocation FROM StockLocation and not hardcode all locations in the procedure ([Location1],[Location2],etc.), but SQL doesn't accept this. How do I