sql-server-2012

Select from SQL Server database with specific range using textbox

扶醉桌前 提交于 2019-12-11 15:19:42
问题 Try conn = New SqlConnection(strcon) conn.Open() Dim str As String = "select * from MYTABLE where Year >='#" & Txtfromyear_reprt.Text & "#' and Year <='#" & Txttoyear_reprt.Text & "#'" da = New SqlDataAdapter(str, conn) Dim ds As New DataSet da.Fill(ds, "MYTABLE") DgvReport.DataSource = ds.Tables("MYTABLE") da.Dispose() conn.Close() Catch ex As Exception MessageBox.Show(ex.Message) End Try I'm working with my school project but I've encountered a problem in which I can't solve. I wrote this

Adding an apostrophe into a dynamic SQL

限于喜欢 提交于 2019-12-11 15:17:28
问题 I would like to ask how can I add an apostrophe into a dynamic SQL. I need to return an SQL statement in one of the columns which has to have apostrophes in itself. I have the following statement: SET @SQL_String = N'INSERT INTO #ReturnTable ( TableName, ColName, SQL_Statement, Value ) VALUES ( ''' + @TableName + ''', ''' + @ColName + ''', ''' + 'SELECT ' + @ColName + ' FROM ' + @TableSchema + '.' + @TableName + ' WHERE ' + @ColName + ' = ' + CAST(@GuidArgument AS NVARCHAR(50)) + ';' +''', (

Date time conversion from timezone to timezone in sql server

徘徊边缘 提交于 2019-12-11 14:47:19
问题 I having an column of UNIX time stamp in my database table, which comes from a system that is in the Kuwait time zone. My database server's time zone is Eastern Time US & Canada . Now I need to convert the UNIX time stamp in to Kuwait time zone date value using an SQL query. Can anyone tell me how I can convert this UNIX time stamp into a Kuwait time zone date value? 回答1: Unix timestamps are integer number of seconds since Jan 1st 1970 UTC. Assuming you mean you have an integer column in your

Loop through a table using Cross apply and UNION ALL the results

a 夏天 提交于 2019-12-11 14:47:12
问题 Trying to write a query which will behave like a foreach Query : select label ,NTILE(10) over(order by label ASC) Quartile INTO #labelTempTab from dbo.ReportFieldsLookup The data will be like : label Quartile ----- -------- la1 1 la2 1 la3 1 sa1 2 sa2 2 sq3 2 ha1 3 ha2 3 ha3 3 ka1 4 ka2 4 kas3 4 Continuation of Query : DECLARE @sql nvarchar(max) SELECT * INTO #SetValuesTable FROM svo_tbl SET @sql = 'SELECT MNUM, Label , LabelValue ,[Property Type] FROM #SetValuesTable ' +' CROSS APPLY (

how to select 3 popular sale product from database?

隐身守侯 提交于 2019-12-11 14:22:20
问题 I need to select 3 most popular product from database, but I don't know how to select it. I using max(col_name), this give me only one item that is the most popular. That's not match my aim. I need the first most popular follow with the second most popular and third most popular product. How to select that in sql server 2012? 回答1: If you wanted to consider dealing with ties for first, second, and third, place, then you may use DENSE_RANK here: SELECT * FROM ( SELECT *, DENSE_RANK() OVER

OPENQUERY throws error when used with WIN2K8\SQL2K12

浪尽此生 提交于 2019-12-11 14:13:40
问题 I'm trying the following Sql query to move my stored procedure result into table SELECT * INTO #tmpTable FROM OPENQUERY(WIN2K8\SQL2K12, 'EXEC vcs_gauge @gauge_name=vs1_bag,@first_rec_time=2014-09-01 09:00:00,@last_rec_time=2014-09-01 10:00:00') following error is thrown, when I execute the query. Incorrect syntax near '\'. I don't want to add linked server .How to resolve this issue? EDIT1 When I do [win2k8\sql2k12], and first execute the following command EXEC sp_serveroption 'YourServer',

SQL server filtering CJK punctuation characters

你离开我真会死。 提交于 2019-12-11 14:12:01
问题 I have few strings in sql server 2012 database that has a CJK space (larger than a space) Unicode decimal : 12288 Hex: 3000 I would like to write a SQL query to filter them using WHERE clause. Any pointers? Thanks, Rajesh 回答1: You can create a Unicode character using the NCHAR() function: SELECT NCHAR(0x3000); -- http://unicode-table.com/en/3000/ You can also use that in a WHERE clause as follows, including also using it with the REPLACE() function to get rid of them. You just need to specify

How to differentiate duplicate column names from different source tables/subqueries by alias in an SQL select statement when using SqlDataReader?

核能气质少年 提交于 2019-12-11 14:01:56
问题 Suppose I have POCO entities being read from a database and they each have "ID" as their primary key column name. If selecting from more than one table or subquery with aliases a and b like select a.*, b.* from a, b , then the selected columns will include two ID columns (a.ID and b.ID), but the source table/subquery aliases are lost. I want to know if there's a way to preserve or dynamically obtain such a top-level alias for the source of the output columns of an arbitrary select query. I

Parallel Date Sales SQL View

柔情痞子 提交于 2019-12-11 13:48:40
问题 I have a challenge which I can't seem to resolve on my own and now need help! I have a requirement to show parallel year date sales via SQL and by that I mean if today (20/08/2015) Customer A has purchased products worth 500, I want to know how much Customer A spent on the same day last year (so 20/08/2014). Here's a SQL fiddle where I've built everything (I reckoned that would be easiest for you guys). I have 3 dimensions (DimProduct, DimDate and DimCustomer), a fact table (FactSales) and a

Database Record Has All Values

自闭症网瘾萝莉.ら 提交于 2019-12-11 13:25:41
问题 I'm using SQL Server 2012 and need some help getting the results I need in a query. My data looks like this: ConsumerID Tag 1000028041 bBROAapp 1000028041 bBROtiva 1000028041 bClsElig 1000028041 bPCAFwd 1000028041 bTOPNoRs 1000028041 bTOPNwRq 1000028041 bTOPActv and I want to select a given ConsumerID only if they have all of the tag values I'm looking for. For example, this selects all records with any of the 3 tags: SELECT ConsumerID FROM BorrowerTags WHERE Tag IN('bBROAapp', 'bBROtiva');