Quantcast
Channel: SQLServerCentral » SQL Server 2012 » SQL Server 2012 - T-SQL » Latest topics
Viewing all 4901 articles
Browse latest View live

Read XML data with related attributes/properites

$
0
0
Hi Team , i have a table with one of the column of xml type. the column contains xml like given below. I want to read this xml from the table and show as below with T-sql query"EmployeeID" [b]"IndustryDome" [/b]"description "where Description value comes from the value of AllDome/ITEM/[b]Dome [/b]/Description whose [b]Dome [/b]equals to [b]IndustryDome [/b]valueEX:[b]1166586 [/b] 3951LX01 [b]Description10[/b]Please help. [code="xml"]<GetEmployeeDetails xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <return xmlns="http://applications.apch1.com/webservice/schema/"> <EmployeeID>1166586</EmployeeID> <BankAccounts> <BankAccount>123456</BankAccount> <BankAccount>7890123</BankAccount> </BankAccounts> <industries> <MarketActivity>Recycling</MarketActivity> <IndustryElectro>1191</IndustryElectro> <IndustryElectri>33LX40</IndustryElectri> <IndustryDome>3951LX01</IndustryDome> <IndustryInter>36.631</IndustryInter> <AllInter> <ITEM> <Inter>28.610</Inter> <description>Description1</description> </ITEM> <ITEM> <Inter>24.660</Inter> <description>Description2</description> </ITEM> <ITEM> <Inter>36.631</Inter> <description>Description3</description> </ITEM> <ITEM> <Inter>36.639</Inter> <description>Description4</description> </ITEM> <ITEM> <Inter>51.479</Inter> <description>Description5</description> </ITEM> </AllInter> <AllDome> <ITEM> <Dome>3LX90505</Dome> <description>Description6</description> </ITEM> <ITEM> <Dome>50910100</Dome> <description>Description7</description> </ITEM> <ITEM> <Dome>28LXLX10</Dome> <description>Description8</description> </ITEM> <ITEM> <Dome>3421LX01</Dome> <description>Description9</description> </ITEM> <ITEM> <Dome>3951LX01</Dome> <description>Description10</description> </ITEM> <ITEM> <Dome>39520000</Dome> <description>Description11</description> </ITEM> </AllDome> </industries> </return></GetEmployeeDetails>[/code]

Row_Number over partition Help

$
0
0
Hi there i am having problems getting my last revision number out when i am trying to use inner joins along with the row_number over partitionI am using 2 tables, tbl_acyear_lookup & tbl_targetstbl_acyear_lookup columns = (pk)- academic_year_id, academic_yearlooks like this:1, 2010/20112, 2011/20123, 2012/2013tbl_targets columns = targetID, Academic_Year_ID,Course_Mode,UK_ENROL, INT_ENROL, Notes, Revision_NumberI have one stored proc that uses the Row_number over partition that looks like this:Select TargetID, Academic_Year_id, Course_Mode, UK_Enrol, Int_Enrol, Notes, Revision_Number from(SELECT ROW_NUMBER() OVER (partition by [Academic_Year_id] order by [Revision_Number] DESC) as [RevNum],TargetID, Academic_Year_id, Course_Mode, Target_Year, UK_Enrol, Int_Enrol, Notes, Revision_NumberFROM tbl_targets where course_mode=@course_mode) RV where (RV.RevNum=1)Now the next store proc needs to use the above but i need to add the Academic_year from the tbl_acyear_lookup table also add filter the target_year ='year 1'Any help Please?

Error while executing a function

$
0
0
SQL Fellows,I am getting one error below which saysA SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.I am trying to execute this below. I have tried lot of possibilities but failed./****** Object: UserDefinedFunction [dbo].[Cat1AndCat2Sector_cat2] Script Date: 12/05/2013 15:13:37 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER OFFGOALTER FUNCTION [dbo].[Cat1AndCat2Sector_cat2]() RETURNS TABLE AS returns DECLARE @Code VARCHAR(MAX)SET @Code = ''select @Code = @Code + Name + ',' from Knowledge_domains where DOMAIN_TYPE ='MASTER'Select @Code as Code,'All' as NameUNIONSelect code,Name from Knowledge_domainswhere DOMAIN_TYPE ='MASTER'order by namePlease can anyone help me out.

Returning Value fo Foreign Key

$
0
0
I have a table tbl_rules.This table will define rules for each role. I have not yet defined the fields for the rules. But the table definition is as below:[code="sql"]Create table tbl_Rules( ID int identity(1,1) not null, Role_ID int not null, primary key (ID), constraint fk_RoleName foreign key (Role_ID) references tbl_Role(ID))[/code]The table tbl_role has two columns as below:[code="other"]ID RoleName1 Manager2 Analyst3 Admin[/code]So far so good. I created the tbl_rules. But what i want to do is when I do select * from tbl_Rules, i want to show as below:ID Role_ID1 Manager2 AdminInstead it shows ID Role_ID1 12 3Is there a way to do this?The goal is to return the select * from tbl_Rules results to a gridview to enable adds and changes.I could do this by doing queries for each column, but I was hoping to make it easier.Not sure if this is even possible.Thanks much,Tina

SQLServerCentral is issuing a public apology to Itzik Ben-Gan

$
0
0
Hi,Please be careful do real research,http://www.sqlservercentral.com/articles/SQLServerCentral/105392/In order to try to win a copy ofMicrosoft SQL Server 2012 HIgh-Performance T-SQL Using Window Functions authored by Mr. Itzik Ben-GanI publish this batchI would like to win one copyRegrets to all of you,CREATE TABLE #Mytable22(gcounter int not null,codesud varchar(10),sequence int,forms char(1),caccount varchar(10),account numeric(18,2),covarname varchar(10),covaryear varchar(10))ALTER TABLE [dbo].[#Mytable22] ADD CONSTRAINT [PK_T_PAG2] PRIMARY KEY CLUSTERED([gcounter] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]CREATE TABLE #Mytable33(gcounter int not null,codesud varchar(5),sequence int,forms char(1),caccount varchar(10),account numeric(18,2),covarname varchar(2),covaryear varchar(4))ALTER TABLE [dbo].[#Mytable33] ADD CONSTRAINT [PK_T_PAG3] PRIMARY KEY CLUSTERED([gcounter] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]Insert into #Mytable33(gcounter,codesud,sequence,forms,caccount,account,covarname,covaryear)SELECT 76,'05961',cast('1' as int),'A','1200000000',cast('9000000.00' as numeric(18,2)),'03','2011'Insert into #Mytable33(gcounter,codesud,sequence,forms,caccount,account,covarname,covaryear)SELECT 77,'05961',1,'A','1200000000',9000000.00,'03','2011'Insert into #Mytable33(gcounter,codesud,sequence,forms,caccount,account,covarname,covaryear)SELECT 1,'05961',3,'F','5120000000',-246395.83,'03','2011' UNION ALLSELECT 2,'03421',32,'F','4319910000',5987405.04,'03','2011' UNION ALLSELECT 3,'03621',3,'F','5120000000',-8710527.17,'03','2011' UNION ALLSELECT 4,'04721',3,'F','5120000000',-16825100.70,'03','2011' UNION ALLSELECT 44,'04721',3,'F','5120000000',-16825100.70,'03','2011' UNION ALLSELECT 45,'04721',3,'F','5120000000',-16825100.70,'03','2011' UNION ALLSELECT 5,'04722',45,'F','4480910600',928.15,'03','2011' UNION ALLSELECT 52,'04722',45,'F','4480910600',928.15,'03','2011' UNION ALLSELECT 53,'04722',45,'F','4480910600',928.15,'03','2011' UNION ALLSELECT 6,'04723',45,'F','4480910100',66064.50,'03','2011'Insert into #Mytable22(gcounter,codesud,sequence,forms,caccount,account,covarname,covaryear)SELECT 1,'05961',3,'F','5120000000',-246395.83,'03','2011' UNION ALLSELECT 2,'03421',32,'F','4319910000',5987405.04,'03','2011' UNION ALLSELECT 3,'03621',3,'F','5120000000',-8710527.17,'03','2011' UNION ALLSELECT 6,'04723',45,'F','4480910100',66064.50,'03','2011'SELECT ROW_NUMBER() OVER (order by b.gcounter) as 'ROWNUMBER',b.codesud as 'ceda2', b.sequence, b.formsFROM #Mytable33 AS bWHERE (b.gcounter IN (SELECT d.gcounter FROM #Mytable22 AS d))

Issue with String concatenation need help please

$
0
0
Dear friends,i have 8 fields - and I have requirement to concatenate using '+' operator with semicolon delimiter but issues is in the Output I get semicolons for the fields that are empty below is my code need hekp please uregnt-------------case when [SLII Request Type] ='Job Posting' and [SmartLaborII Request Status] like 'Pending Approval (Level 4%' and [New Extension or Replacement Audit Flag] like 'FLAG%' then 'Reject – New, Extension, Replacement invalid entry' --'it is jp' else ''end as [ES Fully approved data 1],case when [SLII Request Type] in ('Work Order','Work Order Revision') and [SmartLaborII Request Status] like 'Pending Approval (Level 3%' and [New Extension or Replacement Audit Flag] like 'FLAG%' then 'Reject – New, Extension, Replacement invalid entry'--'it is WO Or WOR' else ''end as [ES Fully approved data 2], case when [SLII Request Type] ='Job Posting' and [SmartLaborII Request Status] like 'Pending Approval (Level 4%' and [Position Duration Audit Flag] = 'FLAG - AC reqs cannot be entered for more than 12 months' then 'Reject – Duration greater than 12 months' else ''end as [ES Fully approved data 3],case when [SLII Request Type] in ('Work Order','Work Order Revision') and [SmartLaborII Request Status] like 'Pending Approval (Level 3%' and [Position Duration Audit Flag] = 'FLAG - AC reqs cannot be entered for more than 12 months' then 'Reject – Duration greater than 12 months' else ''end as [ES Fully approved data 4],case when [SLII Request Type] ='Job Posting' and [SmartLaborII Request Status] like 'Pending Approval (Level 4%' and [Tenure Audit Flag] = 'FLAG - Tenure audit cannot be completed' then'Reject – Invalid GHRMS Worker ID' else ''end as[ES Fully approved data 5],case when [SLII Request Type] in ('Work Order','Work Order Revision') and [SmartLaborII Request Status] like 'Pending Approval (Level 3%' and [Tenure Audit Flag] = 'FLAG - Tenure audit cannot be completed' then'Reject – Invalid GHRMS Worker ID' else ''end as [ES Fully approved data 6],case when [SLII Request Type] ='Job Posting' and [SmartLaborII Request Status] like 'Pending Approval (Level 4%' and [Number of Positions Audit Flag] like 'FLAG%' then 'Reject – Multi Position' else ''end as [ES Fully approved data 7],case when [SLII Request Type] in ('Work Order','Work Order Revision') and [SmartLaborII Request Status] like 'Pending Approval (Level 3%' and [Number of Positions Audit Flag] like 'FLAG%' then 'Reject – Multi Position' else ''end as [ES Fully approved data 8],-----------------------------------------select *, cast ( case when [ES Fully approved data 1] = '' and[ES Fully approved data 2] = '' and [ES Fully approved data 3] = '' and[ES Fully approved data 4] = '' and [ES Fully approved data 5] = '' and [ES Fully approved data 6] = '' and [ES Fully approved data 7] = '' and [ES Fully approved data 8] = '' then '' else [ES Fully approved data 1] + ';' + [ES Fully approved data 2] + ';' + [ES Fully approved data 3] + ';' + [ES Fully approved data 4] + ';' + [ES Fully approved data 5] + ';' + [ES Fully approved data 6] + ';' + [ES Fully approved data 7] + ';' + [ES Fully approved data 8] end as varchar(255)) as [ES Fully approved final data to display] from #tmp_SLII_FINAL------ the O/P comes in--Reject – New, Extension, Replacement invalid entry;Reject – Duration greater than 12 months;;;Reject – Multi Positioninstead as of what I need to be-Reject – New, Extension, Replacement invalid entry;Reject – Duration greater than 12 months;Reject – Multi PositionThanksDJ

SQL Geography Data Type - Test if Point is inside a closed polygon

$
0
0
Ok,Been chewing on this for several hours..I have a closed polygon that coincidently is in the shape of Iowa :) I have a point that is within the state and a point WELL outside it, but I get weird results that I don't expect when I try to get it to tell me that the point is within the polygon. I'm starting to think I am approaching this in my mind wrong.Here is some basic code, sorry about the long coordinates data.[code="sql"]DECLARE @g geography, @pIn geography, @pOut geography SET @g = geography::STPolyFromText('POLYGON((-91.119987 40.705402, -91.129158 40.682148, -91.162498 40.656311, -91.214912 40.643818, -91.262062 40.639545, -91.375610 40.603439, -91.411118 40.572971, -91.412872 40.547993, -91.382103 40.528496, -91.374794 40.503654, -91.385399 40.447250, -91.372757 40.402988, -91.385757 40.392361, -91.418816 40.386875, -91.448593 40.371902, -91.476883 40.390968, -91.490158 40.390762, -91.500221 40.405117, -91.527534 40.410126, -91.529449 40.435043, -91.538689 40.441246, -91.533051 40.455399, -91.579224 40.463718, -91.585869 40.484478, -91.616699 40.504833, -91.622375 40.532864, -91.691917 40.551640, -91.689796 40.581165, -91.716812 40.593399, -91.741547 40.609749, -91.946198 40.608234, -92.192993 40.600060, -92.361328 40.599548, -92.646240 40.591438, -92.717621 40.589645, -93.100731 40.584335, -93.370056 40.580482, -93.562691 40.580807, -93.786079 40.578445, -94.017830 40.574024, -94.238159 40.570972, -94.484993 40.574215, -94.639633 40.575756, -94.920364 40.577229, -95.217171 40.581898, -95.382294 40.584335, -95.767204 40.589046, -95.757271 40.620903, -95.767723 40.643116, -95.876335 40.730434, -95.851509 40.792599, -95.846153 40.848331, -95.834114 40.870300, -95.836258 40.901108, -95.837318 40.974258, -95.860611 41.002651, -95.859253 41.035004, -95.878517 41.065872, -95.857986 41.109188, -95.876396 41.164204, -95.859512 41.166866, -95.858910 41.180538, -95.915810 41.194065, -95.921959 41.207855, -95.910690 41.225246, -95.929939 41.302059, -95.910912 41.308472, -95.897301 41.286865, -95.888817 41.301392, -95.942604 41.340080, -95.939766 41.394810, -95.934776 41.462387, -95.952896 41.472393, -96.006607 41.481960, -96.013161 41.493000, -95.996399 41.511524, -95.993675 41.528111, -96.004303 41.536671, -96.049881 41.524342, -96.085548 41.537529, -96.091644 41.563152, -96.080544 41.576008, -96.111015 41.599014, -96.099014 41.654690, -96.119972 41.684105, -96.121910 41.694923, -96.085266 41.704998, -96.099480 41.731575, -96.099030 41.752987, -96.076126 41.791481, -96.135330 41.862633, -96.159676 41.904163, -96.145576 41.924919, -96.147034 41.966267, -96.184921 41.980698, -96.202545 41.996628, -96.235794 42.001270, -96.238426 42.028450, -96.265182 42.048908, -96.284821 42.123463, -96.351860 42.168194, -96.363205 42.214050, -96.337402 42.229530, -96.332352 42.260315, -96.342575 42.282089, -96.368393 42.298031, -96.389473 42.328796, -96.423866 42.349285, -96.411453 42.380924, -96.417320 42.414783, -96.397583 42.441799, -96.395767 42.467407, -96.439087 42.489246, -96.479935 42.517136, -96.489029 42.564034, -96.500633 42.573891, -96.488190 42.580486, -96.512535 42.629761, -96.540855 42.662411, -96.562729 42.668518, -96.626228 42.708359, -96.640396 42.748608, -96.632668 42.776840, -96.600563 42.799564, -96.587334 42.835388, -96.572815 42.834354, -96.555901 42.846668, -96.537201 42.896915, -96.543953 42.913876, -96.514626 42.952393, -96.516838 42.986469, -96.498711 43.012062, -96.519699 43.051521, -96.479263 43.061897, -96.461784 43.075596, -96.460495 43.087887, -96.451195 43.126324, -96.472801 43.209099, -96.486931 43.217926, -96.558289 43.225506, -96.566673 43.239651, -96.559250 43.253281, -96.570404 43.263630, -96.578812 43.290092, -96.540245 43.307678, -96.522575 43.356987, -96.524734 43.384247, -96.557388 43.400749, -96.588791 43.435562, -96.583473 43.481945, -96.597992 43.499874, -96.460136 43.499744, -96.060738 43.498566, -95.866615 43.498978, -95.464493 43.499577, -95.396278 43.500370, -94.920197 43.499413, -94.859573 43.500072, -94.454987 43.498146, -94.246544 43.498993, -93.973717 43.500343, -93.653481 43.500809, -93.500618 43.500534, -93.054184 43.501495, -93.027016 43.501316, -92.557831 43.500294, -92.452995 43.499496, -92.077370 43.499187, -91.730217 43.499603, -91.610954 43.500656, -91.223434 43.500835, -91.235771 43.464710, -91.210785 43.424076, -91.198112 43.370537, -91.176918 43.353970, -91.078369 43.313320, -91.066299 43.280704, -91.068924 43.257919, -91.161224 43.147594, -91.168442 43.082905, -91.159622 43.081200, -91.152084 43.001331, -91.138992 42.925907, -91.093300 42.871452, -91.081902 42.783375, -91.066040 42.744923, -90.999054 42.707066, -90.919281 42.680683, -90.892418 42.678246, -90.745483 42.657005, -90.694664 42.637932, -90.664253 42.571392, -90.639091 42.555714, -90.625580 42.528561, -90.638329 42.509361, -90.651772 42.494698, -90.648346 42.475643, -90.605827 42.460560, -90.563583 42.421837, -90.491043 42.388783, -90.441597 42.360073, -90.427681 42.340633, -90.417984 42.263924, -90.407173 42.242645, -90.367729 42.210209, -90.323601 42.197319, -90.230934 42.159721, -90.191574 42.122688, -90.176086 42.120502, -90.166649 42.103745, -90.168098 42.061043, -90.150536 42.033428, -90.142670 41.983963, -90.154518 41.930775, -90.195839 41.806137, -90.255310 41.781738, -90.304886 41.756466, -90.326027 41.722736, -90.341133 41.649090, -90.339348 41.602798, -90.348366 41.586849, -90.423004 41.567272, -90.434967 41.543579, -90.454994 41.527546, -90.540840 41.525970, -90.600700 41.509586, -90.658791 41.462318, -90.708214 41.450062, -90.779900 41.449821, -90.844139 41.444622, -90.949654 41.421234, -91.000694 41.431084, -91.027489 41.423508, -91.055786 41.401379, -91.073280 41.334896, -91.102348 41.267818, -91.101524 41.231522, -91.056320 41.176258, -91.018257 41.165825, -90.990341 41.144371, -90.957787 41.104359, -90.954651 41.070362, -90.960709 40.950504, -90.983276 40.923927, -91.049210 40.879585, -91.088905 40.833729, -91.092751 40.761547, -91.119987 40.705402))', 4326);SET @pIn = geography::STPointFromText('POINT( -90.6204165 41.5795478)',4326)SET @pOut = geography::STPointFromText('POINT( -80.6204165 31.5795478)',4326)SELECT Poly = @g, pIn = @pIn, pOut = @pOutSELECT DistanceInMetersIn = @g.STDistance( @pIn ), DistanceInMetersOut = @g.STDistance( @pOut ), STIntersectsIn = @g.STIntersects( @pIn ), STIntersectsOut = @g.STIntersects( @pOut )SELECT STIntersectionIn = @g.STIntersection( @pIn ).ToString(), STIntersectionOut = @g.STIntersection( @pOut ).ToString()GO[/code]Here is the second and third result sets and they confuses me immensely.[code="sql"]DistanceInMetersIn DistanceInMetersOut STIntersectsIn STIntersectsOut ---------------------- ---------------------- -------------- --------------- 7863.61743130497 0 0 1 (1 row(s) affected)STIntersectionIn STIntersectionOut-------------------------- -------------------------------GEOMETRYCOLLECTION EMPTY POINT (-80.6204165 31.5795478)(1 row(s) affected)[/code]As I read that there is a distance of about 7864 meters, this is close to what I would expect, so that's ok. The point outside I would expect a distance as well so that is confusing.. Then we have the intersects, it says that the point inside does NOT intersect but the one outside DOES, this is backed up by the intersection values. WHAT?!?So am I crazy or am I just not thinking about this from the right direction. In my mind I see a closed polygon, I want to see if that point is inside that polygon, and I'm not seeing that here..CEWII

Using Exec at insted of Linked servers

$
0
0
I have a fairly long query that joins tables on residing on different physical servers.While using linked servers works, I'm trying to replace linked servers with the exec ('query') at option as the latter is significantly faster.However, I'm not sure if it's possible when you have a query with subqueries and the 'WITH" clause hitting several physical servers.Thank you for suggestions.LenPS. I want to avoid rewriting this as a stored proc for now.

display order by houseno

$
0
0
i have table house no like this below coloum.........house_no3-13-103-13-200/a3-13-450/a3-13-1345/b3-13-123-13-43-13-567/c3-13-832/a3-13-943i want table like this....3-13-43-13-103-13-123-13-200/a3-13-450/a3-13-567/c3-13-832/a3-13-9433-13-1345/bpl write the quarie..................

Query to find user who last modified user roles/access?

$
0
0
Hello all-I was recommended to this site for all the wealth of knowledge and I was hoping ya'll could assist me with this. I am new to the DBA world (only 2 months in) and have been granted the power of the "accidental DBA" you could say.I would like to know if there is a way to find out who changed a users roles/access WITHOUT using the audit function. For example, if a user account was created and given SA access then changed to read only, how can I find out who made that change? I tried searching for an answer, but kept getting no results. I'm thinking this may tie into the sys.sysusers view?Any help would be very much appreciated and I apologize if I seem to be too noobish.

SQL - Does Geography Point In A Closed Polygon Problem (2nd try)

$
0
0
Ok,Been chewing on this for several hours..I have a closed polygon that coincidentally is in the shape of Iowa :) I have a point that is within the state and a point WELL outside it, but I get weird results that I don't expect when I try to get it to tell me that the point is within the polygon. I'm starting to think I am approaching this in my mind wrong.Here is some basic code, sorry about the long coordinates data.[code="sql"]DECLARE @g geography, @pIn geography, @pOut geography SET @g = geography::STPolyFromText('POLYGON((-91.119987 40.705402, -91.129158 40.682148, -91.162498 40.656311, -91.214912 40.643818, -91.262062 40.639545, -91.375610 40.603439, -91.411118 40.572971, -91.412872 40.547993, -91.382103 40.528496, -91.374794 40.503654, -91.385399 40.447250, -91.372757 40.402988, -91.385757 40.392361, -91.418816 40.386875, -91.448593 40.371902, -91.476883 40.390968, -91.490158 40.390762, -91.500221 40.405117, -91.527534 40.410126, -91.529449 40.435043, -91.538689 40.441246, -91.533051 40.455399, -91.579224 40.463718, -91.585869 40.484478, -91.616699 40.504833, -91.622375 40.532864, -91.691917 40.551640, -91.689796 40.581165, -91.716812 40.593399, -91.741547 40.609749, -91.946198 40.608234, -92.192993 40.600060, -92.361328 40.599548, -92.646240 40.591438, -92.717621 40.589645, -93.100731 40.584335, -93.370056 40.580482, -93.562691 40.580807, -93.786079 40.578445, -94.017830 40.574024, -94.238159 40.570972, -94.484993 40.574215, -94.639633 40.575756, -94.920364 40.577229, -95.217171 40.581898, -95.382294 40.584335, -95.767204 40.589046, -95.757271 40.620903, -95.767723 40.643116, -95.876335 40.730434, -95.851509 40.792599, -95.846153 40.848331, -95.834114 40.870300, -95.836258 40.901108, -95.837318 40.974258, -95.860611 41.002651, -95.859253 41.035004, -95.878517 41.065872, -95.857986 41.109188, -95.876396 41.164204, -95.859512 41.166866, -95.858910 41.180538, -95.915810 41.194065, -95.921959 41.207855, -95.910690 41.225246, -95.929939 41.302059, -95.910912 41.308472, -95.897301 41.286865, -95.888817 41.301392, -95.942604 41.340080, -95.939766 41.394810, -95.934776 41.462387, -95.952896 41.472393, -96.006607 41.481960, -96.013161 41.493000, -95.996399 41.511524, -95.993675 41.528111, -96.004303 41.536671, -96.049881 41.524342, -96.085548 41.537529, -96.091644 41.563152, -96.080544 41.576008, -96.111015 41.599014, -96.099014 41.654690, -96.119972 41.684105, -96.121910 41.694923, -96.085266 41.704998, -96.099480 41.731575, -96.099030 41.752987, -96.076126 41.791481, -96.135330 41.862633, -96.159676 41.904163, -96.145576 41.924919, -96.147034 41.966267, -96.184921 41.980698, -96.202545 41.996628, -96.235794 42.001270, -96.238426 42.028450, -96.265182 42.048908, -96.284821 42.123463, -96.351860 42.168194, -96.363205 42.214050, -96.337402 42.229530, -96.332352 42.260315, -96.342575 42.282089, -96.368393 42.298031, -96.389473 42.328796, -96.423866 42.349285, -96.411453 42.380924, -96.417320 42.414783, -96.397583 42.441799, -96.395767 42.467407, -96.439087 42.489246, -96.479935 42.517136, -96.489029 42.564034, -96.500633 42.573891, -96.488190 42.580486, -96.512535 42.629761, -96.540855 42.662411, -96.562729 42.668518, -96.626228 42.708359, -96.640396 42.748608, -96.632668 42.776840, -96.600563 42.799564, -96.587334 42.835388, -96.572815 42.834354, -96.555901 42.846668, -96.537201 42.896915, -96.543953 42.913876, -96.514626 42.952393, -96.516838 42.986469, -96.498711 43.012062, -96.519699 43.051521, -96.479263 43.061897, -96.461784 43.075596, -96.460495 43.087887, -96.451195 43.126324, -96.472801 43.209099, -96.486931 43.217926, -96.558289 43.225506, -96.566673 43.239651, -96.559250 43.253281, -96.570404 43.263630, -96.578812 43.290092, -96.540245 43.307678, -96.522575 43.356987, -96.524734 43.384247, -96.557388 43.400749, -96.588791 43.435562, -96.583473 43.481945, -96.597992 43.499874, -96.460136 43.499744, -96.060738 43.498566, -95.866615 43.498978, -95.464493 43.499577, -95.396278 43.500370, -94.920197 43.499413, -94.859573 43.500072, -94.454987 43.498146, -94.246544 43.498993, -93.973717 43.500343, -93.653481 43.500809, -93.500618 43.500534, -93.054184 43.501495, -93.027016 43.501316, -92.557831 43.500294, -92.452995 43.499496, -92.077370 43.499187, -91.730217 43.499603, -91.610954 43.500656, -91.223434 43.500835, -91.235771 43.464710, -91.210785 43.424076, -91.198112 43.370537, -91.176918 43.353970, -91.078369 43.313320, -91.066299 43.280704, -91.068924 43.257919, -91.161224 43.147594, -91.168442 43.082905, -91.159622 43.081200, -91.152084 43.001331, -91.138992 42.925907, -91.093300 42.871452, -91.081902 42.783375, -91.066040 42.744923, -90.999054 42.707066, -90.919281 42.680683, -90.892418 42.678246, -90.745483 42.657005, -90.694664 42.637932, -90.664253 42.571392, -90.639091 42.555714, -90.625580 42.528561, -90.638329 42.509361, -90.651772 42.494698, -90.648346 42.475643, -90.605827 42.460560, -90.563583 42.421837, -90.491043 42.388783, -90.441597 42.360073, -90.427681 42.340633, -90.417984 42.263924, -90.407173 42.242645, -90.367729 42.210209, -90.323601 42.197319, -90.230934 42.159721, -90.191574 42.122688, -90.176086 42.120502, -90.166649 42.103745, -90.168098 42.061043, -90.150536 42.033428, -90.142670 41.983963, -90.154518 41.930775, -90.195839 41.806137, -90.255310 41.781738, -90.304886 41.756466, -90.326027 41.722736, -90.341133 41.649090, -90.339348 41.602798, -90.348366 41.586849, -90.423004 41.567272, -90.434967 41.543579, -90.454994 41.527546, -90.540840 41.525970, -90.600700 41.509586, -90.658791 41.462318, -90.708214 41.450062, -90.779900 41.449821, -90.844139 41.444622, -90.949654 41.421234, -91.000694 41.431084, -91.027489 41.423508, -91.055786 41.401379, -91.073280 41.334896, -91.102348 41.267818, -91.101524 41.231522, -91.056320 41.176258, -91.018257 41.165825, -90.990341 41.144371, -90.957787 41.104359, -90.954651 41.070362, -90.960709 40.950504, -90.983276 40.923927, -91.049210 40.879585, -91.088905 40.833729, -91.092751 40.761547, -91.119987 40.705402))', 4326);SET @pIn = geography::STPointFromText('POINT( -90.6204165 41.5795478)',4326)SET @pOut = geography::STPointFromText('POINT( -80.6204165 31.5795478)',4326)SELECT Poly = @g, pIn = @pIn, pOut = @pOutSELECT DistanceInMetersIn = @g.STDistance( @pIn ), DistanceInMetersOut = @g.STDistance( @pOut ), STIntersectsIn = @g.STIntersects( @pIn ), STIntersectsOut = @g.STIntersects( @pOut )SELECT STIntersectionIn = @g.STIntersection( @pIn ).ToString(), STIntersectionOut = @g.STIntersection( @pOut ).ToString()GO[/code]Here is the second and third result sets and they confuses me immensely.[code="sql"]DistanceInMetersIn DistanceInMetersOut STIntersectsIn STIntersectsOut ---------------------- ---------------------- -------------- --------------- 7863.61743130497 0 0 1 (1 row(s) affected)STIntersectionIn STIntersectionOut-------------------------- -------------------------------GEOMETRYCOLLECTION EMPTY POINT (-80.6204165 31.5795478)(1 row(s) affected)[/code]As I read that there is a distance of about 7864 meters, this is close to what I would expect, so that's ok. The point outside I would expect a distance as well so that is confusing.. Then we have the intersects, it says that the point inside does NOT intersect but the one outside DOES, this is backed up by the intersection values. WHAT?!?So am I crazy or am I just not thinking about this from the right direction. In my mind I see a closed polygon, I want to see if that point is inside that polygon, and I'm not seeing that here..CEWII

Check to see if multiple VALUES exsit in a table

$
0
0
I know how to check for a sinle vlaue but how do I chekc to see if multiple values exist. I need to check for certain email addresses from a list that I have. Let us say I ahve 3 email addresses, I want to check for all of them in a table and for eevery email address that is present I want to print something like "You email address is XXX" and if one of those 3 is not found my results should look like "You email address is XXX"YYYYY not found"You email address is ZZZZ"Please suggest. I'm atatching some TSQL that I tried on [b][AdventureWorks2012].[Person].[EmailAddress][/b][code="sql"]/****** Select ALL if where an email address is present in the list ******/SELECT EmailAddressID,EmailAddress FROM [AdventureWorks2012].[Person].[EmailAddress] WHERE EmailAddress IN ('ken0@adventure-works.com', --1'terri0@adventure-works.com', --2'roberto0@adventure-works.com',--3'gail0@adventure-works.com', --4'jossef0@adventure-works.com',--5'dylan0@adventure-works.com',--6'diane1@adventure-works.com',--7'gigi0@adventure-works.com',--8-- The below emails do not exist. '25terri0@adventure-works.com',--9'25roberto0@adventure-works.com',--10'25rob0@adventure-works.com'--11)/*Results:EmailAddressID EmailAddress8 diane1@adventure-works.com7 dylan0@adventure-works.com5 gail0@adventure-works.com9 gigi0@adventure-works.com6 jossef0@adventure-works.com1 ken0@adventure-works.com3 roberto0@adventure-works.com2 terri0@adventure-works.com*/-- Test to see if a single email address is present IF EXISTS ( SELECT EmailAddress FROM [AdventureWorks2012].[Person].[EmailAddress] WHERE EmailAddress IN ('25rob0@adventure-works.com') ) BEGIN SELECT 'Email address is presnt' ENDELSE SELECT 'Email Address is NOT present'; /*Results:Email Address is NOT present*/-- Test if multiple values are present:IF EXISTS ( SELECT EmailAddress FROM [AdventureWorks2012].[Person].[EmailAddress] WHERE EmailAddress IN ( 'ken0@adventure-works.com', --1 'terri0@adventure-works.com', --2 'roberto0@adventure-works.com',--3 'gail0@adventure-works.com', --4 'jossef0@adventure-works.com',--5 'dylan0@adventure-works.com',--6 'diane1@adventure-works.com',--7 'gigi0@adventure-works.com',--8 -- The below emails do not exist. '25terri0@adventure-works.com',--9 '25roberto0@adventure-works.com',--10 '25rob0@adventure-works.com'--11 ) ) BEGIN SELECT 'Email address is presnt' ENDELSE SELECT 'Email Address is NOT present'; /*Results:Email Address is present*/[/code]when I check multiples using EXISTS it works as per its design and says YES even if a single item is present. Please advise.

display order by like 1,2,3,4,5...............plz write quarie

$
0
0
Examples of values I want to put in orderhouseno3-13-13-13-3/a3-13-3/b3-13-2/a3-13-43-13-63-13-5/a3-13-4/ci want output like this belowhouseno3-13-13-13-2/a3-13-3/a3-13-3/b3-13-43-13-4/c3-13-5/a3-13-6

Run ASPX file from Stored Procedure?

$
0
0
Hey,After my Stored Procedure has run, I need to call a https://site/blablabla.aspx file. Can this be done from my Stored Procedure?Thx,Raymond

what is the use of Over Clause

$
0
0
I would like to know when and how to use over clause in sql 20012 with proper example.

select only up to first '-' only

$
0
0
I Have table like this......House_no6-16-1-26-1/26-1/786-12/56-3-124 ,hyderabad6-3/26-3-19876 ,yuyuselect only first '-' only.............I WANT OUTPUT LIKE THIS order ...........6-16-1/26-1/786-3/26-12/5

Merge - Pros and cons

$
0
0
Hi there,Please any one help me out to understand what is MERGE ? and when to use it?Also explain me the Pros and cons.Thanks in Advance

differences in rounding / converting strings

$
0
0
Hi all,first of all: I know some best practices and work-arounds when working with float numbers, I just want to understand :)An older topic tried to explain the difference between[code="sql"]SELECT ROUND ('6.465',2) --- result 6.46[/code]and[code="sql"]SELECT ROUND (6.465,2) --- result 6.47[/code]with[quote]It's because you're relying on an implicit conversion from a string to a decimal data type which SQL server will do to 2 decimal places by default...[/quote]Allright:[code="sql"]SELECT ROUND (CONVERT(DECIMAL(3,2),'6.465'),2) --- result 6.47[/code]Now please explain this:[code="sql"]SELECT ROUND('0.285',2) -- 0.28SELECT ROUND(0.285,2) -- 0.29SELECT ROUND (CONVERT(DECIMAL(3,2),'0.285'),2) --- result 0.29[/code]The string value does not seem to be converted to decimal with 2 decimal places.MS is on the safe side with mentioning [quote]the last digit is always an estimate[/quote]But because the result of the estimate is always the same, I would like to know:* how is a string value exactly implicitly converted?* how exactly does the estimation work, that in case of doubt rounds a value up or off?Thank You!

Best options for this scenarion

$
0
0
Hi,I have two dynamic pivot tables that I need to join. The problem I'm running into is that at execution, one is ~7500 characters and the other is ~7000 characters. I can't set them both up as CTEs and query, the statement gets truncated. I can't use a temp table because those get dropped when the query finishes. I can't use a real table because the insert statement gets truncated.Do I have any other good options, or am I in [url=http://www.sqlservercentral.com/articles/T-SQL/72129/]Spacklesville[/url]?For reference, [url=http://www.sqlservercentral.com/Forums/Topic1486814-3077-3.aspx#bm1519413]this is what I'm doing[/url].Thanks!

Splitting column values iin multiple columns and assigning it to a row

$
0
0
How do I write a query using the split function for the following requirementI have a table in the following wayIdentity Name Col1 Col2 Col31 Test1 1,2,3 200,300,400 3,4,62 Test2 3,4,5 300,455,600 2,3,8I want an output in the following formatIdentity Name Col1 Col2 Col31 Test1 1 200 31 Test1 2 300 41 Test1 3 400 62 Test2 3 300 22 Test2 4 455 32 Test2 5 600 8If you see the data, first element in col1 is matched to first element in col2 and 3 after splitting the string.
Viewing all 4901 articles
Browse latest View live