Jump to content

sql experts please come


4Vikram

Recommended Posts

17 minutes ago, JollyBoy said:

nuv rasina query ikada vey.. sample columns and update column


select A.[MWC_ID]
      ,A.[CATEGORY_1]
      ,A.[CATEGORY_2]
      ,A.[STRING_VALUE1]
      ,A.[STRING_VALUE2]
      ,STATE_ID = ROW_NUMBER() over (partition by A.[STRING_VALUE1] order by A.[STRING_VALUE1]) 
FROM [tbl_APP_DROPDOWN_VALUES] A
WHERE A.[CATEGORY_1] = 'State'
--AND A.[STRING_VALUE1] = 1
AND   A.[CATEGORY_2] = 'County'

 

my values are like this 

 

MWC_ID    CATEGORY_1    CATEGORY_2    STRING_VALUE1    STRING_VALUE2    STATE_ID
1    State    County    Alabama     Autauga County    1
2    State    County    Alabama     Baldwin County    2
3    State    County    Alabama     Barbour County    3

 

But Sate_ID should get values as 1,1,1 nduku ante State_ID value should be 1 to each state

Link to comment
Share on other sites

  • Replies 65
  • Created
  • Last Reply

Top Posters In This Topic

  • 4Vikram

    21

  • JollyBoy

    10

  • mettastar

    4

  • kittaya

    4

Top Posters In This Topic

 

6 hours ago, 4Vikram said:


select A.[MWC_ID]
      ,A.[CATEGORY_1]
      ,A.[CATEGORY_2]
      ,A.[STRING_VALUE1]
      ,A.[STRING_VALUE2]
      ,STATE_ID = ROW_NUMBER() over (partition by A.[STRING_VALUE1] order by A.[STRING_VALUE1]) 
FROM [tbl_APP_DROPDOWN_VALUES] A
WHERE A.[CATEGORY_1] = 'State'
--AND A.[STRING_VALUE1] = 1
AND   A.[CATEGORY_2] = 'County'

 

my values are like this 

 

MWC_ID    CATEGORY_1    CATEGORY_2    STRING_VALUE1    STRING_VALUE2    STATE_ID
1    State    County    Alabama     Autauga County    1
2    State    County    Alabama     Baldwin County    2
3    State    County    Alabama     Barbour County    3

 

But Sate_ID should get values as 1,1,1 nduku ante State_ID value should be 1 to each state

;with SS  as

(select 
      ,A.[STRING_VALUE1],STATE_ID
          , ROW_NUMBER() over (partition by A.[STRING_VALUE1] order by A.[STRING_VALUE1])  RN 
FROM [tbl_APP_DROPDOWN_VALUES] ) 

UPDATE  T SET T.STATE_ID = S.RN FROM [tbl_APP_DROPDOWN_VALUES] T inner join  SS S on S.[STRING_VALUE1] = T.[STRING_VALUE1]

Link to comment
Share on other sites

bhayya another way is having state dimension table and calling it 

DIM_State

Masterstate Number, StateName, StateCode, County, Zip Code, DataStamp, Stamp. 

masterstateNumber will be unique for a given state.

as it will be static table you can use in multiple queries.

 

Link to comment
Share on other sites

5 hours ago, JollyBoy said:

 

;with SS  as

(select 
      ,A.[STRING_VALUE1],STATE_ID
          , ROW_NUMBER() over (partition by A.[STRING_VALUE1] order by A.[STRING_VALUE1])  RN 
FROM [tbl_APP_DROPDOWN_VALUES] ) 

UPDATE  T SET T.STATE_ID = S.RN FROM [tbl_APP_DROPDOWN_VALUES] T inner join  SS  on S.[STRING_VALUE1] = T.[STRING_VALUE1]

Bro thanks for this but I used another it worked as well... Will use this also and see again... Vere id through pm chesta respond to that... 

Link to comment
Share on other sites

5 hours ago, JollyBoy said:

 

;with SS  as

(select 
      ,A.[STRING_VALUE1],STATE_ID
          , ROW_NUMBER() over (partition by A.[STRING_VALUE1] order by A.[STRING_VALUE1])  RN 
FROM [tbl_APP_DROPDOWN_VALUES] ) 

UPDATE  T SET T.STATE_ID = S.RN FROM [tbl_APP_DROPDOWN_VALUES] T inner join  SS  on S.[STRING_VALUE1] = T.[STRING_VALUE1]

*7*^

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...