Search Results

Search found 37012 results on 1481 pages for 'sql query'.

Page 135/1481 | < Previous Page | 131 132 133 134 135 136 137 138 139 140 141 142  | Next Page >

  • distance between two points across land using sql server

    - by dpwb
    I am looking to calculate the shortest distance between two points inside SQL Server 2008 taking into account land mass only. I have used the geography data type along with STDistance() to work out point x distance to point y as the crow flies, however this sometimes crosses the sea which i am trying to avoid. I have also created a polygon around the land mass boundary I am interested in. I believe that I need to combine these two methods to ensure that STDistance always remains within polygon - unless there is a simpler solution. Thanks for any advice

    Read the article

  • T-SQL Where statement - OR

    - by Zyphrax
    Sorry for the vague title but I really didn't know what title to give to this problem: I have the following result set: ID Data Culture 1 A nl-NL 2 B nl-NL 3 C nl-NL 4 A en-GB 5 B en-GB 6 A en 7 B en 8 C en 9 D en 10 A nl I would like to mimic the ASP.Net way of resource selection, user Culture (nl-NL) SELECT Data FROM Tbl WHERE Culture = 'nl-NL' Or when there are no results for the specific culture, try the parent Culture (nl) SELECT Data FROM Tbl WHERE Culture = 'nl' Or when there are no results for the parent culture, try the default Culture (en) SELECT Data FROM Tbl WHERE Culture = 'en' How can I combine these SELECT-statements in one T-SQL statement? I'm using LINQ so a LINQ expression would be even greater. The OR-statement won't work, because I don't want a mix of cultures. The ORDER BY-statement won't help, because it returns multiple records per culture.

    Read the article

  • SQL Server: position based on marks

    - by Rhys
    I am using SQL Server 2008. I have a Student table in which there are following fields: 1. StudentId, 2. StudentName, 3. Marks . I want to get a resultset in which there should be a column named “Position”. Something like “Select StudentId,StudentName,Marks, as Position from Student...” so that, depending on the marks a student scored, i can evaluate them as the 1st, 2nd or 20th position. If students have the same marks, then they have the same position. Thanks. Rhys

    Read the article

  • Saving a huge dataset into SQL table in a XML column - MS SQL, C#.Net

    - by NLV
    Hello all I'm having a requirement where i've to save a dataset which has multiple tables in it in a sql table XML column by converting into an XML. The problem is that in some cases the dataset grows extremely huge and i get OutOfMemoryException. What i basically do is that i convert the dataset into an xml file and save it in the local disk and then load the XML again and send it as a stored procedure parameter. But when i write the dataset xml into the disk the file sizes over 700 Mb and when i load it in the XMLDocument object in memory i get OutOfMemoryException. How can get the dataset xml without saving it in a file and re-reading it again? Thank You NLV

    Read the article

  • SQL Select Permissions

    - by Brandi
    I have a database that I need to connect to and select from. I have an SQL Login, let's call it myusername. When I use the following, no SELECT permission shows up: SELECT * FROM fn_my_permissions ('dbo.mytable', 'OBJECT') GO Several times I tried things like: USE mydatabase GO GRANT SELECT TO myusername GO GRANT SELECT ON DATABASE::mydatabase TO myusername GO GRANT SELECT ON mytable TO myusername GO It says the queries execute successfully, but there is never any difference in the first query. What simple thing am I missing to grant database level select permissions. As a note, I made double sure it was the correct user, correct database, and I have already tried granting table level select permissions. So far I keep getting the error: SELECT permission denied on object 'mytable', database 'mydatabase', schema 'dbo'. Any ideas what I'm missing? Thanks in advance.

    Read the article

  • sql exception when transferring project from usb to c:\

    - by jello
    I'm working on a C# windows program with Visual Studio 2008. Usually, I work from school, directly on my usb drive. But when I copy the folder on my hard drive at home, an sql exception is unhandled whenever I try to write to the database. it is unhandled at the conn.Open(); line. here's the exception unhandled Database 'L:\system\project\the_project\the_project\bin\Debug\PatientMonitoringDatabase.mdf' already exists. Choose a different database name. Cannot attach the file 'C:\Documents and Settings\Administrator\My Documents\system\project\the_project\the_project\bin\Debug\PatientMonitoringDatabase.mdf' as database 'PatientMonitoringDatabase'. it's weird, because my connection string says |DataDirectory|, so it should work on any drive... here's my connection string: string connStr = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\PatientMonitoringDatabase.mdf; " + "Initial Catalog=PatientMonitoringDatabase; " + "Integrated Security=True";

    Read the article

  • SQL Exec T-SQL statement?

    - by salvationishere
    I am trying to list all of the columns from whichever Adventureworks table I choose. What T-sQL statement or stored proc can I execute to see this list of all columns? I want to use my C# web app to input one input parameter = table_name and then get a list of all the column_names as output. Right now I am trying to execute the sp_columns stored proc which works, but I can't get just the one column with select and exec combined. Does anybody know how to do this?

    Read the article

  • SQL Server 2005 RIGHT OUTER JOIN not working

    - by CheeseConQueso
    I'm looking up access logs for specific courses. I need to show all the courses even if they don't exist in the logs table. Hence the outer join.... but after trying (presumably) all of the variations of LEFT OUTER, RIGHT OUTER, INNER and placement of the tables within the SQL code, I couldn't get my result. Here's what I am running: SELECT (a.first_name+' '+a.last_name) instructor, c.course_id, COUNT(l.access_date) course_logins, a.logins system_logins, MAX(l.access_date) last_course_login, a.last_login last_system_login FROM lsn_logs l RIGHT OUTER JOIN courses c ON l.course_id = c.course_id, accounts a WHERE l.object_id = 'LOGIN' AND c.course_type = 'COURSE' AND c.course_id NOT LIKE '%TEST%' AND a.account_rights > 2 AND l.user_id = a.username AND ((a.first_name+' '+a.last_name) = c.instructor) GROUP BY c.course_id, a.first_name, a.last_name, a.last_login, a.logins, c.instructor ORDER BY a.last_name, a.first_name, c.course_id, course_logins DESC Is it something in the WHERE clause that's preventing me from getting course_id's that don't exist in lsn_logs? Is it the way I'm joining the tables? Again, in short, I want all course_id's regardless of their existence in lsn_logs.

    Read the article

  • Variable as numeric sent to stored procedure (SQL Server 2005)

    - by TimCarrett
    I see that with SQL Server 2005 you can pass a parameter as numeric e.g. create procedure dbo.TestSP @Param1 numeric as But what does this equate to? E.g. Numeric(10,0), Numeric(9,2), etc? We have some Developers here who are using this instead of the correct definition for the field that this parameter is going to be used against e.g. instead of using Numeric(10, 0) for the parameter @Param1. Also are there any underlying performance issues with using Numeric instead of the data type defined against the field in the table? Many thanks.

    Read the article

  • T-SQL SQL Server - Stored Procedure with parameter

    - by Ricardo Conte
    Please, the first TSQL works FINE, the second does not. I guess it must be a simple mistake, since I am not used to T-SQL. Thank you for the answers. R Conte. * WORKS FINE ******************* (parm hard-coded) ALTER PROCEDURE rconte.spPesquisasPorStatus AS SET NOCOUNT ON SELECT pesId, RTRIM(pesNome), pesStatus, pesPesGrupoRespondente, pesPesQuestionario, pesDataPrevistaDisponivel, pesDataPrevistaEncerramento, pesDono FROM dbo.tblPesquisas WHERE (pesStatus = 'dis') ORDER BY pesId DESC RETURN Running [rconte].[spPesquisasPorStatus]. pesId Column1 pesStatus pesPesGrupoRespondente pesPesQuestionario pesDataPrevistaDisponivel pesDataPrevistaEncerramento pesDono 29 XXXXXXXXX xxxxx dis 17 28 5/5/2010 08:21:12 5/5/2010 08:21:12 1 28 Xxxxxxxx xxxxxxxxxxxxx dis 16 27 5/5/2010 07:44:12 5/5/2010 07:44:12 1 27 Xxxxxxxxxxxxxxxxxxxxxxx * DOES NOT WORK ************** (using a parm; pesStatus is nchar(3)) ALTER PROCEDURE rconte.spPesquisasPorStatus (@pPesStatus nchar(3) = 'dis') AS SET NOCOUNT ON SELECT pesId, RTRIM(pesNome), pesStatus, pesPesGrupoRespondente, pesPesQuestionario, pesDataPrevistaDisponivel, pesDataPrevistaEncerramento, pesDono FROM dbo.tblPesquisas WHERE (pesStatus = @pPesStatus) ORDER BY pesId DESC RETURN Running [rconte].[spPesquisasPorStatus] ( @pPesStatus = 'dis' ). pesId Column1 pesStatus pesPesGrupoRespondente pesPesQuestionario pesDataPrevistaDisponivel pesDataPrevistaEncerramento pesDono No rows affected. (0 row(s) returned) @RETURN_VALUE = 0 Finished running [rconte].[spPesquisasPorStatus]

    Read the article

  • SQL Split function.

    - by Wardy
    Hi guys, I'm looking for a way to do this ... SELECT FirstName, LastName, Split(AddressBlock, ' ', 1), Split(AddressBlock, ' ', 2), PostCode FROM Contacts The arguments I want to pass are ... The address The separator (current situation requires 2 spaces but this might be a comma or a space followed by a comma) or something else (it varies). The address part I want to return (i don't always need all parts of the split result). I seem to be able to find a few examples of splitting functions about the internet but they return a table containing the entire set of split parts. My SQL skills aren't that great so I need the answer to be ultra simple. I'm always working with nvarchar data and the function needs to be reusable.

    Read the article

  • T-SQL Picking up active IDs from a comma seperated IDs list

    - by hammayo
    I have two tables "Product" having following structure: ProductID,ProductName, IsSaleTypeA, IsSaleTypeB, IsSaleTypeC 1, AAA, N, N, N 2, BBB, N, Y, N -- active 3, CCC, N, N, N 4, DDD, Y, N, N -- active 5, EEE, N, N, N 6, FFF, N, N, N 7, FFE, N, N, N 8, GGG, N, N, N 9, HHH, Y, N, N -- active The second table "ProductAllowed" having following structure where ProductIDs is a comma separated string filed having mix of active and inactive product ids based on their IsSaleType mode. ProductCode, ProductIDs AMRLSPN, "1,2" AMRLOFD, "1,3" BLGHVF, "2,4,6" BLGHVO, "2,4" BLGHVD, "3,5" BLGSDO, "0" CHOHVF, "1,6" CHOHVP, "1,2,7,8" ... ... Q: Is there a t-sql query that will return a list of active records from the "ProductAllowed" table if any of three IsSaleType fileds is/are switched on for a product. Based on the sample data the ProductAllowed records should return following records. AMRLSPN BLGHVF BLGHVO BLGSDO CHOHVP This needs to be applied in a SQLSERVER 2000 database containing aprox 150000 records. Thanks

    Read the article

  • Convert T-SQL function to PL/SQL

    - by llasarov
    can you help me convert following T-SQL funcntion into Oracle. The function converts a string like service|nvretail;language|de;yyyy|2011; to a table. The main problem I have is the usage of the temp table. I could not find any equivalent to it in Oracle. CREATE FUNCTION [dbo].[TF_ConvertPara] ( @parastringNVARCHAR(max) ) RETURNS @para TABLE ( [Key] varchar(max), [Value] varchar(max) ) begin DECLARE @NextString NVARCHAR(40) DECLARE @Pos1 INT DECLARE @Pos2 INT DECLARE @NextPos INT DECLARE @Delimiter1 NCHAR=';' DECLARE @Delimiter2 NCHAR='|' if substring(@paraString, len(@paraString) - 1, 1) <> @Delimiter1 SET @paraString = @paraString + @Delimiter1 SET @Pos1 = charindex(@Delimiter1, @paraString) WHILE (@pos1 <> 0) BEGIN SET @NextString = substring(@paraString, 1, @Pos1 - 1) SET @paraString = substring(@paraString, @pos1 + 1, len(@paraString)) SET @pos1 = charindex(@Delimiter1, @paraString) SET @Pos2 = charindex(@Delimiter2, @NextString) if (@Pos2 > 0) begin insert into @para values (substring(@NextString, 1, @Pos2 - 1), substring(@NextString, @Pos2 + 1, len(@NextString))) end END return; end Thank you in advance.

    Read the article

  • Sql server indexed view

    - by Jose
    OK, I'm confused about sql server indexed views(using 2008) I've got an indexed view called AssignmentDetail when I look at the execution plan for select * from AssignmentDetail it shows the execution plan of all the underlying indexes of all the other tables that the indexed view is supposed to abstract away. I would think that the execution plan woul simply be an clustered index scan of PK_AssignmentDetail(the name of the clustered index for my view) but it doesn't. There seems to be no performance gain with this indexed view what am I supposed to do? Should I also create a non-clustered index with all of the columns so that it doesn't have to hit all the other indexes? Any insight would be greatly appreciated

    Read the article

  • Weird SQL Server 2005 Collation difference between varchar() and nvarchar()

    - by richardtallent
    Can someone please explain this: SELECT CASE WHEN CAST('iX' AS nvarchar(20)) > CAST('-X' AS nvarchar(20)) THEN 1 ELSE 0 END, CASE WHEN CAST('iX' AS varchar(20)) > CAST('-X' AS varchar(20)) THEN 1 ELSE 0 END Results: 0 1 SELECT CASE WHEN CAST('i' AS nvarchar(20)) > CAST('-' AS nvarchar(20)) THEN 1 ELSE 0 END, CASE WHEN CAST('i' AS varchar(20)) > CAST('-' AS varchar(20)) THEN 1 ELSE 0 END Results: 1 1 On the first query, the nvarchar() result is not what I'm expecting, and yet removing the X make the nvarchar() sort happen as expected. (My original queries used the '' and N'' literal syntax to distinguish varchar() and nvarchar() rather than CAST() and got the same result.) Collation setting for the database is SQL_Latin1_General_CP1_CI_AS.

    Read the article

  • Better way to write this SQL

    - by AngryHacker
    I have the following table: create table ARDebitDetail(ID_ARDebitDetail int identity, ID_Hearing int, ID_AdvancedRatePlan int) I am trying to get the latest ID_AdvancedRatePlan based on a ID_Hearing. By latest I mean with the largest ID_ARDebitDetail. I have this query and it works fine. select ID_AdvancedRatePlan from ARDebitDetails where ID_Hearing = 135878 and ID_ARDebitDetail = ( select max(ID_ARDebitDetail) from ARDebitDetails where ID_AdvancedRatePlan > 0 and ID_Hearing = 135878 ) However, it just looks ugly and smells bad. Is there a way to rewrite it in a more concise manner?

    Read the article

  • Converting SQL to LINQ to XML

    - by Morano88
    I'm writing the following code to convert SQL to LINQ and then to XML: SqlConnection thisConnection = new SqlConnection(@"Data Source=3BDALLAH-PC;Initial Catalog=XMLC;Integrated Security=True;Pooling=False;"); thisConnection.Open(); XElement eventsGive = new XElement("data", from c in ?????? select new XElement("event", new XAttribute("start", c.start), new XAttribute("end",c.eend), new XAttribute("title",c.title), new XAttribute("Color",c.Color), new XAttribute("link",c.link))); Console.WriteLine(eventsGive); The name of the table is "XMLC" and I want to refer to it. How can I do that? When I put its name directly VS gives an error. Also when I say thisConnection.XMLC it doesn't work.

    Read the article

  • Setting up a SQL server outside the domain

    - by Ben
    Hi, im very new to this. I've set up an account "SQLBOX" thats on the a network, but not connected to the domain. I have installed an instance of SQL Server 2008 and am trying to connect to it from another machine on the network but am getting "Cannot connect to "SQLBOX"". From the "SQLBOX" i can connect to sqlservers on the domain, but not vice-versa. Any help would be greatly appreciated. Sorry if the description isn't great. EDIT I can ping the box from a machine on the domain

    Read the article

  • How to count incrementally in SQL SERVER

    - by joe
    Hi Folks, I am assigned a problem which i am not sure how to write it in SQL SEVER (version 5/8) yet. Here is the simple query and its output: Select location, date_time, Item_sold From Product Location Date_time Item_sold VA 12/10/2010 1:30:00 PM Candy VA 12/10/2010 3:30:00 PM Chips VA 12/13/2010 12:50:00 AM Wine DC 12/13/2010 8:00:00 AM Gum DC 12/13/2010 12:30:00 PM Bags DC 12/13/2010 1:16:00 PM Cheese DC 12/13/2010 12:00:00 AM Hotdog NJ 12/15/2010 12:00:00 AM Coffee NJ 12/15/2010 1:15:00 PM Beers NJ 12/15/2010 3:45:00 AM Cream Here is my desired output, which I guess a while/for loop or a pivot function could do the job but my experience is not there yet. Basically, I need to count the number of item sold from the Item_sold column incrementally (base line date starts from 12/8 to 12/9, 12/8 to 12/10, 12/8 to 12/11, 12/8 to 12/12...) I was wondering if anyone could edcuate and solve this problem. Many thanks in advance, Joe Location 12/8 |12/8-12/9 |12/8-12/10 |12/8 - 12/11 |12/8 - 12/12 |12/8 - 12/13 VA 0 0 2 0 0 3 DC 0 0 0 0 0 4

    Read the article

  • What does xp_qv do in SQL Server?

    - by Chris
    Last night one of our SQL servers developed some major problems and after a colleague stopped, started, and all the usual things it started checking and rebuilding databases and is now running an extended stored procedure called "xp_qv". The internet seems to be very short of information on what this procedure does or anythign like that so I was hoping somebody here might be able to help. I should add that I assume it is meant to be running so the question isn't "Can I stop it" or anything like that, its just curiosity in what it is doing in the hope that it will help determine how long before things are usable again...

    Read the article

  • SQL Server Agent 2005 job runs but no output

    - by alimack
    Essentially I have a job which runs in BIDS and as as a stand lone package and while it runs under the SQL Server Agent it doesn't complete properly (no error messages though). The job steps are: 1) Delete all rows from table; 2) Use For each loop to fill up table from Excel spreasheets; 3) Clean up table. I've tried this [MS page][1] (steps 1 & 2), didn't see any need to start changing from Server side security. Also SQLServerCentral.com for [this page][2], no resolution. How can I get error logging or a fix? Note I've reposted this from Server Fault as it's one of those questions that's not pure admin or programming. I have logged in as the proxy account I'm running this under, and the job runs stand alone but complains that the Excel tables are empty?

    Read the article

  • Linq to sql Incorrect varchar length

    - by scott
    I have a table with a nullable varchar(50) column in it. When I am updating the value through linq to sql and trace the call in profiler it is defining the parameter as varchar(36). This is obviously causing some minor issues when we are trying to insert data that is between 37 and 50 characters long. I have tried removing the table and re-adding it to the design surface but the same thing happens. I also tried removing that property and adding it manually, same issue. When I look at the designer.cs code it shows the attribute properly: [Column(Storage="_Name", DbType="VarChar(50)")] I am out of ideas, anybody seen this before? Every other column is correct.

    Read the article

  • SQL Server T-SQL statement to replace/delete sub-strings

    - by StefanE
    Hi, I have a table with 6 columns containing HTML content with some markups in it and now when moving to a new designed site most of this HTML code has to be deleted. More or less all tags except <B> and </B>. Is there a nice way of doing this, identify all tags end delete them within the data? I'm sure there are no < symbols in the test so a regular expression would maybe work? My alternative is to fetch every row, process it and update the database but I'm guessing this is possible to do in T-SQL directly. My server is an MSSQL 2008 and is located in a hosted environment but I can fetch a local copy if needed. Thanks, Stefan

    Read the article

  • MS SQL replace sequence of same characters inside Text Field (TSQL only)

    - by zmische
    I have a text column varchar(4000) with text: 'aaabbaaacbaaaccc' and I need to remove all duplicated chars - so only one from sequence left: 'abacbac' It should not be a function, Procedure or CLR - Regex solution. Only true SQL select. Currently I think about using recursive WITH clause with replace 'aa'-'a', 'bb'-'b', 'cc'-'c'. So recursion should cycle until all duplicated sequences of that chars would be replaced. DO you have another solution, perhaps more Permormant one? PS: I searched through this site about different replace examples - they didnt suit to this case.

    Read the article

< Previous Page | 131 132 133 134 135 136 137 138 139 140 141 142  | Next Page >