sql-server-2008-r2

How does SQL Server determine the order of the columns when you do a `SELECT *`?

£可爱£侵袭症+ 提交于 2019-12-04 23:55:14
How does SQL Server determine the order of the columns when you do a SELECT * ? I know "Order By" is essential for ordering the data , but I expected the column names to be consistent. Note: My code is not dependent on the actual order the columns are returned. I just want to know how SQL Server decides to order the column names. Of about 20 computers my team is using, one of them behaves differently. Any difference deserves to be investigated. The column name ordering appears to be the same for all computers when we open SQL Server Management Studio. When our application makes a query is when

Insert into table from temporary table

泄露秘密 提交于 2019-12-04 23:23:00
I have the following table: Example : create table test ( col1 varchar(10), col2 varchar(20), col3 varchar(30) ); Now I want to insert two values by variables and last one by #temp table. #Temp : create table #temp ( col3 varchar(30) ); #Temp : Contains col3 ----- A1 A2 A3 Insertion into test table: Declare @col1 varchar(10) = 'A' Declare @col1 varchar(20) = 'B' Declare @sql varchar(max) SET @SQL = N'insert into test values('+@col1+','+@col2+',........); EXEC(@SQL) /* How to insert `@col3` from #temp to test table*/ Expected Result : col1 col2 col3 ------------------ A B A1 A B A2 A B A3 Note

SQL Server dbo.sysdiagrams is a user table or system table

Deadly 提交于 2019-12-04 22:36:32
When use Database Diagrams in a simple database, SQL Server create a dbo.sysdiagrams table in the Table\Systam Tables node (in Microsoft management studio\object explorer). But sysdiagrams table marked as user table in SQL Server. you can get user table by below query. SELECT * FROM sys.tables t WHERE OBJECTPROPERTY(t.object_id,'IsUserTable') = 1 I don't know that sysdiagram table is a system table or is a user table. Exists microsoft_database_tools_support with value 1 In the extended property of sysdiagram, that determine this table created automatically. Alain Tésio System tables are used

is not a recognized built-in function name

巧了我就是萌 提交于 2019-12-04 22:26:48
Created a function CREATE FUNCTION Split_On_Upper_Case(@Temp VARCHAR(1000)) RETURNS VARCHAR(1000) AS BEGIN DECLARE @KeepValues AS VARCHAR(50) SET @KeepValues='%[^ ][A-Z]%' WHILE PATINDEX(@KeepValues COLLATE Latin1_General_Bin,@Temp)>0 SET @Temp=STUFF(@Temp,PATINDEX(@KeepValues COLLATE Latin1_General_Bin,@Temp)+1,0,' ') RETURN @Temp END When iam trying to exexute this SELECT Split_On_Upper_Case('SaiBharath') It gives an error "'Split_On_Upper_Case' is not a recognized built-in function name.".Can someone please explain this Add [dbo] in prefix and then execute as same : SELECT [dbo].[Split_On

IIF(…) not a recognized built-in function

南楼画角 提交于 2019-12-04 22:20:48
I'm trying to use this in Microsoft SQL Server 2008 R2: SET @SomeVar = @SomeOtherVar + IIF(@SomeBool, 'value when true', 'value when false') But I get an error: IIF(...) is not a recognized built-in function name Is IIF() only compatible with a later version? Is there an alternate function I can use? Richard As others have said, IIF comes from SQL 2012. Before then, you can use CASE : SET @SomeVar = @SomeOtherVar + CASE WHEN @SomeBool THEN 'value when true' ELSE 'value when false' END What's New in SQL Server 2012, Programmability Enhancements : SQL Server 2012 introduces 14 new built-in

How to Connect to SQL Server 2008 R2 Using EF and MVC 3

▼魔方 西西 提交于 2019-12-04 20:47:26
I am simply trying to learn MVC 3 and following a book from Wrox. Things were fine until I tried to execute a small exercise. I am getting an error which is very common. I have tried everything but could't find what the problem is. Can somebody help me out. My configuration. installed VS201 and then used WebPlatForm Installer to install SP1. Which did installed SP1 and installed MVC3 templates and framework as well on my machine. So far so good. After that I installed SQL Server 2008 R2 Developer Edition, again so far so good. I followed step by step the exercise and found an error which is

Pass table value param to stored procedure using PetaPoco

隐身守侯 提交于 2019-12-04 20:31:37
问题 For while I am trying to call SQL Server 2008 R2 stored procedure using PetaPoco. My stored procedure accepts a table valued parameter. How I can call the stored procedure in petapoco with table value param? Here what I am trying to do: var db = new PetaPoco.Database("repikaciskaBaza"); DataTable table = new DataTable(); DataColumn id = table.Columns.Add("id", type: typeof(Int32)); for (int i = 0; i < 10;i++ ) { DataRow row = table.NewRow(); row["id"] = i; table.Rows.Add(row); } var param =

FluentNhibernate support for SQL Server 2008 R2

删除回忆录丶 提交于 2019-12-04 20:11:02
I want to implement a Fluent Nhibernate application with SQL Server 2008 R2. I am in a confusion whether Fluent Nhibernate 1.2 supports SQL Server 2008 R2. If supports what will be the configuration. Does it looks like below? var config = Fluently.Configure() .Database( MsSqlConfiguration .MsSql2008R2 .ConnectionString(@"Data Source=.\SQLEXPRESS;AttachDbFilename='FNHLD.mdf';Integrated Security=True;User Instance=True")) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<NHibernateRepository<T>>()) .BuildConfiguration(); As a matter of fact, even MsSql2005 dialect will work on SQL Server 2008 R2

Select parent if all children meet criteria

荒凉一梦 提交于 2019-12-04 19:20:55
问题 I have tables set up like so: Parent ------ id, ... Child ----- id, parent_id, x, y I want to find the Parents, or the distinct parent_id(s), if all of the rows in Child containing a given parent_id meet a criteria involving x and y(in my case x = y). For example: Parent ------ id 1 2 3 Child id, parent_id, x, y 1, 1, 2, 3 2, 1, 3, 4 3, 2, 5, 5 4, 2, 6, 7 5, 3, 8, 8 6, 3, 9, 9 would result in 3. Currently, I have a query that finds parent_ids that any of the children meet the criteria. I then

How to take substring from field between specific chars

二次信任 提交于 2019-12-04 18:36:55
I have field which contain a value like: F28_TIT245_0_90A_OOC_LCL by AARBITMA(aarbitma@LC13UPE-CIM) I want to take the name between '(' and '@' which is "aarbitma" . How can I do it? I'm running on SQL Server 2008R2 -- there are no checks for wrong input text -- this is TODO to be done yourself DECLARE @text VARCHAR(100) DECLARE @start INT DECLARE @end INT SET @text = 'F28_TIT245_0_90A_OOC_LCL by AARBITMA(aarbitma@LC13UPE-CIM)' SELECT @start = PATINDEX('%(%@%', @text) SELECT @end = CHARINDEX('@', @text, 0) SELECT SUBSTRING(@text, @start+1, @end-@start-1) MSDN: PATINDEX() CHARINDEX() SUBSTRING(